|
public class WebViewActivity extends Activity { |
|
|
|
WebView myWebView; |
|
|
|
private final static String TAG = "WebView"; |
|
|
|
@Override |
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
setContentView(R.layout.webview); |
|
|
|
myWebView = (WebView) findViewById(R.id.webview); |
|
|
|
new WebViewTask().execute(); |
|
} |
|
|
|
private class WebViewTask extends AsyncTask<Void, Void, Boolean> { |
|
String sessionCookie; |
|
CookieManager cookieManager; |
|
|
|
@Override |
|
protected void onPreExecute() { |
|
CookieSyncManager.createInstance(WebViewActivity.this); |
|
cookieManager = CookieManager.getInstance(); |
|
|
|
sessionCookie = new PersistentConfig(getApplicationContext()).getCookieString(); |
|
if (sessionCookie != null) { |
|
/* delete old cookies */ |
|
cookieManager.removeSessionCookie(); |
|
} |
|
super.onPreExecute(); |
|
} |
|
protected Boolean doInBackground(Void... param) { |
|
/* this is very important - THIS IS THE HACK */ |
|
SystemClock.sleep(1000); |
|
return false; |
|
} |
|
@Override |
|
protected void onPostExecute(Boolean result) { |
|
if (sessionCookie != null) { |
|
cookieManager.setCookie("yourdomain.com", sessionCookie); |
|
CookieSyncManager.getInstance().sync(); |
|
} |
|
WebSettings webSettings = myWebView.getSettings(); |
|
webSettings.setJavaScriptEnabled(true); |
|
webSettings.setBuiltInZoomControls(true); |
|
myWebView.setWebViewClient(new WebViewClient() { |
|
@Override |
|
public boolean shouldOverrideUrlLoading(WebView view, String url) { |
|
return super.shouldOverrideUrlLoading(view, url); |
|
} |
|
|
|
}); |
|
myWebView.loadUrl("https://yourdomain.com/anything"); |
|
} |
|
} |
|
} |
does it still work with android 4.4 built API 21