PersistentCookieStore 相关问题新手求解,谢谢大神

sulinly 2017-09-17 04:01:04
PersistentCookieStore persistentCookieStore
=MyApplication.getInstance().getCookieStore();

上面是网上抄的段代码,其中MyApplication显示:cannot resolve symbol "MyApplication",这个需要加入啥子依赖库?impot 啥子包?或者是其他问题?
下面是全文:
   private void syncCookie(Context context, String url){
try{
Log.e("Nat:syncCookie.url", url);

CookieSyncManager.createInstance(context);

CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();// 移除
cookieManager.removeAllCookie();
String oldCookie = cookieManager.getCookie(url);
if(oldCookie != null){
Log.e("Nat: oldCookie", oldCookie);
}

PersistentCookieStore persistentCookieStore
= MyApplication.getInstance().getCookieStore();
for (cz.msebera.android.httpclient.cookie.Cookie cookie : persistentCookieStore.getCookies()) {

String cookieString = cookie.getName() + "=" + cookie.getValue()
+ "; domain=" + cookie.getDomain()
+ "; path=" + cookie.getPath();
cookieManager.setCookie(url, cookieString);
CookieSyncManager.getInstance().sync();
}
String newCookie = cookieManager.getCookie(url);
if(newCookie != null){
Log.d("Nat: newCookie", newCookie);
}
}catch(Exception e){
Log.e("Nat: failed", e.toString());
}
}
...全文
453 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sulinly 2017-09-28
  • 打赏
  • 举报
回复
引用 3 楼 jklwan 的回复:
抄代码没抄全,MyApplication是自定义的application,getInstance().getCookieStore()当然就是获取application中的PersistentCookieStore对象
谢谢,大概明白了。非常感谢!
sulinly 2017-09-20
  • 打赏
  • 举报
回复
引用 1 楼 zanjiaowei 的回复:
把MyApplication换成getApplication.
PersistentCookieStore persistentCookieStore =getApplication.getInstance().getCookieStore(); 上面把MyApplication换成getApplication后,.getInstance().显示:cannot resolve symbol "getInstance",怎么办呢?
jklwan 2017-09-20
  • 打赏
  • 举报
回复
抄代码没抄全,MyApplication是自定义的application,getInstance().getCookieStore()当然就是获取application中的PersistentCookieStore对象
smile_邝野 2017-09-18
  • 打赏
  • 举报
回复
把MyApplication换成getApplication.

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧