Reputation: 93
I'm trying to open http:// link that will do single sign on SSO logic for Blackboard Collaborate.
The link will check for authentication, and if I'm authenticated will forward me to open the app.
In Chrome browser it's working fine, as it's redirecting me to Blackboard app installed on my device.
The issue is when I'm trying to open the http:// link in WebView inside my app. The http:// link is redirected to another http:// links then will redirect to intent:// link. In that case the WebView is showing error message (Unable to find host name intent://blah.blah.blah)
Here's my code, I'm trying to set an exception for 'intent://' schema to do something else. But I don't know what to do!
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Open Blackboard app
if (url != null && url.startsWith("intent://")) {
Log.d("AG_LOG", "intent:// found");
Intent intent = new Intent();
intent.setData(Uri.parse(url));
view.getContext().startActivity(intent);
return true;
} else {
view.loadUrl(url, headers);
view.setWebChromeClient(new MyChromeClient());
view.setWebViewClient(new MyWebViewClient());
return false;
}
}
}
I tried Intent.ACTION_VIEW but not worked!
Upvotes: 1
Views: 226
Reputation: 93
Finally I got the solution :)
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Open Blackboard app
if (url != null && url.startsWith("intent://")) {
Log.d("AG_LOG", "intent:// found");
try {
Intent sessionIntnet = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); // Here the MAGIC
sessionIntnet.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
view.getContext().startActivity(sessionIntnet);
} catch (URISyntaxException e) {
e.printStackTrace();
Toast.makeText(MyActivity.this, "Unable to open app!", Toast.LENGTH_LONG).show();
}
return true;
} else {
view.loadUrl(url, headers);
view.setWebChromeClient(new MyChromeClient());
view.setWebViewClient(new MyWebViewClient());
return false;
}
}
}
The new intent is the result of the parsesed intent using Intent.ParseUri() and pass Intent.URI_INTENT_SCHEME as a second parameter.
Upvotes: 2