I have a problem with implementing user authentification in a WebView.
As API Docs say, I need to load URL "http://example.com/?key=abc" then User enters his login & password and then he's redirected to webpage "myapp://token#access_token=123456".
All I need is to load this in a WebView and return to my application with that "123456" token. The first problem is that WebView doesn't support custom protocols and it gives me an error "ERR_UNKNOWN_URL_SCHEME".
Second problem is that I don't fully understand how to return to my application with page data.
In AndroidManifest.xml I have this:
<activity
android:name="(appname)"
android:label="@string/app_name"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:scheme="myapp"
android:host="token"/>
</intent-filter>
</activity>
In Main.java file I have the following code:
Intent i = new Intent(Main.this, LoginWebViewActivity.class);
startActivityForResult(i, 1);
and in LoginWebActivity.java I have the following code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webviewact);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://example.com/?key=abc");
}
I see one fast solution: Open this link in external browser, however, I don't understand how can my application get data from external browser.