简体   繁体   中英

Android webview keep user logged in

I am developing an android application. It is a simple application containing a webview which will load my mvc website.

First page of my application is login page.Once user logs in to the system application page is shown.

Requirement - Is it possible for webview to remember the credentials and allow the auto log in to system when he/she visits next time?

need help. Following is main activity code.

            public class MainActivity extends Activity {
            WebView webView;
            String loginUrl = "mail.xyzabcd.com";

            @Override
            public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Adds Progress bar Support
            this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.activity_main);

            webView = (WebView) findViewById(R.id.webView1);
            webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
            WebSettings settings = webView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setDomStorageEnabled(true);
            settings.setLightTouchEnabled(true);
            settings.setSupportZoom(true);
            settings.setBuiltInZoomControls(true);
            webView.loadUrl(loginUrl);

            // on clicking a link load it in the same link
            webView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false;
            }

            @Override
            public void onPageFinished(WebView view, String url) {              
            }
            });
            }

Web View is just a widget which is used to display. It cannot by itself remember data across sessions (if the activity is killed).

What you could do though is to create a resource file that would store the user id and password (based in the logic you want) and then have the Web View check to see if this resource file is present. If present, you could extract details from there. You could do your own encryption as well to secure the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM