Skip to content

Instantly share code, notes, and snippets.

@dspachos
Created November 2, 2018 10:04
Show Gist options
  • Save dspachos/41f3c68d0d6f0741816df75c4c179af9 to your computer and use it in GitHub Desktop.
Save dspachos/41f3c68d0d6f0741816df75c4c179af9 to your computer and use it in GitHub Desktop.
Automatic login for Flarum in an Android WebView
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setDomStorageEnabled(true);
myWebView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
view.loadUrl(
"javascript:(function() { " +
"var identification = 'dummyusername';" +
"var password = 'dummypassword';" +
"var remember = 'true';" +
"if (!user) {app.session.login({identification: identification,password: password,remember: remember},{errorHandler: console.log('error')}).then(function () {return window.location.reload();})};" +
"})()");
}
});
myWebView.loadUrl("https://forum.selfpainrelief.eu");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment