안드로이드 웹뷰에서 쿠키가 안 먹힐 때
메인 액티비티에서 쿠키에 대해 싱크도 해주고 만들어주고... 암튼 만들어줘야 한다.위치 : MainActivity.java
Source:
import android.webkit.CookieSyncManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setLayout();
CookieSyncManager.createInstance(this);
// set web view client
mWebview.setWebViewClient(new WebClient());
WebSettings set = mWebview.getSettings();
// set java script enable.
set.setJavaScriptEnabled(true);
set.setBuiltInZoomControls(true);
mWebview.loadUrl("http://???????????");
}
class WebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url){
CookieSyncManager.getInstance().sync();
}
}
@Override
protected void onResume(){
super.onResume();
CookieSyncManager.getInstance().startSync();
}
@Override
protected void onPause(){
super.onPause();
CookieSyncManager.getInstance().stopSync();
}
댓글 없음:
댓글 쓰기