4
私はこのアプリを閉じるためにセッションクッキーを保持するためにWebViewを取得しようとしています。ユーザーが再びログインするとログインできます。これは非常に新しく、これを理解しようとしています。私は何を変更する必要がありますか?私はばかだと親切にしてください。それがあなたのために簡単なら、私のためにそれを編集する必要があるとしても、説明的にしてください。Cookie Webviewを保存しますか?
CookieManagerとCookieSyncManagerの両方をインポートしましたが、次に何をすべきかについてIDEAがありません。私は...
package com.template.WebViewTemplate;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
public class WebViewTemplate extends Activity {
private WebView myWebView;
/** Called when the activity is first created. */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) { // Enables browsing to previous pages with the hardware back button
myWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myWebView = (WebView) findViewById(R.id.webview); // Create an instance of WebView and set it to the layout component created with id webview in main.xml
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("http://zuneboards.com/forums/mgc_chatbox.php?do=view_chatbox"); // Specify the URL to load when the application starts
//myWebView.loadUrl("file://sdcard/"); // Specify a local file to load when the application starts. Will only load file types WebView supports
myWebView.setWebViewClient(new WebViewKeep());
myWebView.setInitialScale(1); // Set the initial zoom scale
myWebView.getSettings().setBuiltInZoomControls(true); // Initialize zoom controls for your WebView component
myWebView.getSettings().setUseWideViewPort(true); // Initializes double-tap zoom control
}
private class WebViewKeep extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}ドキュメントのすべてを読んでいると、ユーザーは再度ログインする必要はありませんし、私はちょうどそれを把握することはできませんので、それはクッキーを保存するようにする方法を把握しようと時間を費やしています}
CookiesManager、ここでは説明アンドロイドドキュメント[この記事] [1] [1]:http://stackoverflow.com/questions/2566485/webview-and-cookies-on-android –