Currently, I am still in the proccess of learning Android development so please excuse me if this question of mine is not easily understandable for you.
I create an Android app that is showing a set of list using RecyclerView and when the user click each of the names on the list, it will redirect them to a set of different websites and it will be displayed in WebView. Each of those websites have a different login page. I don't control those websites. Those websites turn off their cookies. Now, is it possible to save user's Username and Password in this situation?
When I included Facebook, Instagram and Twitter, my app able to save the Username and Password (maybe because they are saving cookies?). But if I try the particular websites (with the special situation) that I wanted to add, the Username and Password is not saved.
Since the setSavePassword method is deprecated, I can not found other way to implement saving Username and Password. I have read about SharedPreferences, JavaScript and Autofill several times, but I don't know how to properly implement them into my app. Because from most of what I have read, it is suggested that it will need a login page first to save the Username and Password.
This is my WebView code.
public class WebViewActivity extends AppCompatActivity {
private WebView webView;
String url = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
webView = findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
websettings.setDomStorageEnabled(true);
websettings.setJavaScriptEnabled(true);
webView.getSettings().setAppCachePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/cache");
webView.getSettings().setDatabasePath(getApplicationContext().getFilesDir().getAbsolutePath() + "/databases");
if (Build.VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true);
} else {
CookieManager.getInstance().setAcceptCookie(true);
}
webView.loadUrl(url);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
}
...
}
...
}
Thank you.