नीचे मेरी कोड के साथ, मैं एक कुकी को बचाने के लिए सक्षम किया गया है, लेकिन जैसे ही मैं अनुप्रयोग को बंद के रूप में कुकी गायब हो जाता है।एक एंड्रॉइड वेबव्यू में कुकी को हमेशा से कैसे सहेजना है?
यह कैसे होता है और मैं इसे कैसे हल कर सकता हूं?
package com.jkjljkj
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CookieSyncManager.createInstance(getBaseContext());
// Let's display the progress in the activity title bar, like the
// browser app does.
getWindow().requestFeature(Window.FEATURE_PROGRESS);
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 1000);
}
});
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//Users will be notified in case there's an error (i.e. no internet connection)
Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
CookieSyncManager.getInstance().startSync();
CookieSyncManager.getInstance().sync();
//This will load the webpage that we want to see
webview.loadUrl("http://");
}
}
CookieSyncManager अब हटाई गई है, CookieManager का उपयोग करें। http: // stackoverflow।कॉम/प्रश्न/30502411/कुकीज़yncmanager-is-now-deprecated-what-can-i-use-इसके बजाय –
@Rahul Sahni मैंने कोशिश की लेकिन अगर ऐप बंद करें और फिर से खोलें तो मुझे लॉगिन करना होगा और सभी कुकीज़ खो जाएंगी! क्या आप मुझे बता सकते हैं कि समस्या क्या हो सकती है? – user1788736