Reputation: 103
Our app lets users login into other services. A user clicks on a Login button on a website (in some mobile browser) or on another app, which takes them to our app through a deep link. The user completes the login flow in our app. We'd then like to automatically redirect the user to where they started from, whether on a mobile browser or another app. I can't figure out how to do this in the general case.
My understanding is that redirecting to another app requires that app to have deep linking enabled. (Question #0: Is this true, or is there a way to do this even if the app doesn't have deep linking?)
Everyone I've asked seems to think this is only possible for apps and not mobile browsers, i.e. that there is no way to deep link into mobile browsers or otherwise redirect the user to them (except to the phone's default browser). But this doesn't make sense to me, since a mobile browser is just a kind of mobile app.
Also, there's at least an OS-level way to go back to another app or browser: both iOS and Android have such a back button, and it works with apps (even if they don't have deep linking) and mobile browsers. I don't know if this is accessible to us developers, but it suggests that the functionality might be possible.
Someone suggested to me that there was some way to redirect a user to an app by using something like com.appName
, but I haven't been able to find anything online to support this.
To make this clearer, here's an example of a desired flow that captures the more subtle challenges:
Example 1. The user is using the Brave mobile browser, which is not their phone's default browser. 2. On some website, they click a Login button that takes them to our app, where they finish the login flow. 3. Our app takes them back to Brave, where they website the button was on updates to reflect the fact that they've completed the login process.
Upvotes: 2
Views: 6071
Reputation: 4060
You can URL in the mobile browser using Intent
.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
//Or
//Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(i);
You can also open specific browsers using something along the following lines.
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setPackage("com.android.chrome");
try {
startActivity(i);
} catch (ActivityNotFoundException e) {
// Chrome is probably not installed
// Try with the default browser
i.setPackage(null);
startActivity(i);
}
You could also allow the user to choose the browser.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
// Note the Chooser below. If no applications match,
// Android displays a system message.So here there is no need for try-catch.
startActivity(Intent.createChooser(intent, "Browse with"));
Here's the link to the official docs for further reference.
Upvotes: 1