我四处寻找解决方案,但这里是:
我有一个应用程序,我想准确跟踪有人从我的域安装它的时间(假设该应用程序是 app.apk)。
所以我有一个登陆页面,它基本上是一个下载 apk 的链接,一旦有人进入该页面,我就会在他们的设备上设置一个 cookie,我现在想知道的是,是否可能以及我如何才能在应用程序中读取该 cookie。 (假设我的 cookie 的路径是 domain example.com/android/
)
谢谢。
最佳答案
在 webView 中加载网页并在服务器上读取此页面的 cookie 的代码 fragment 。
myWebView = new WebView(this);
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);
}
});
setContentView(myWebView);
CookieManager.getInstance().removeSessionCookie();
myWebView.loadUrl(URL);
//你要读取cookie的地方
CookieManager cookieManager = CookieManager.getInstance();
final String cookie = cookieManager.getCookie(URL);
Log.i(TAG, "cookie " + cookie);
关于android - 从特定域的 webview 获取 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8817929/