开发者

Can I use a cookie from the native browser within my app's WebView?

I want users that visit my website using their phone to get a cookie from me. Later, when they use my application, I want them to use the same cookie from the previous session.

开发者_开发百科

Is that at all possible?

If not, is there a different way to maintain state information between browser sessions and app sessions?

Thanks for your time!


From the Android documentation (http://developer.android.com/reference/android/webkit/WebView.html)

Cookie and window management

For obvious security reasons, your application has its own cache, cookie store etc.—it does not share the Browser application's data. Cookies are managed on a separate thread, so operations like index building don't block the UI thread. Follow the instructions in CookieSyncManager if you want to use cookies in your application.

So the short answer is no, you can't access anything the main browser has stored in your app's WebView.

I'm not entirely sure what you can do to get around it. Can't you just store the session data on your server in a database and link it to a user account. Then you can have the app store their login details and automatically log in, which means they won't need to type their username/pass every time they use the app and it can just sync their session details each time. To the user, it should look fairly seamless.


If they are using a webview within your app then it is possible to retrieve and save a cookie for reuse in your application e.g. to make a web service call.

But if you want to get a cookie from the main Android web browser, I don't think that's possible.


As far as I know it is not possible (I was looking for the same thing). There are solutions which try to identify users statistically and should be able to create the same User Id both on Apps and Browser (you can check AdTruth)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜