'packageManager.queryIntentActivities: Check if resolved app is a browser
On Android, I'm using packageManager.queryIntentActivities to return a list of apps that can handle a URL.
I only want to open the URL in an app that is specifically meant for that URL, i.e. the Twitter app for twitter urls, but I don't want to open the URL using a generic browser like Chrome or Firefox.
Is there a way to check if the returned app is specifically meant for that URL or if it's a generic browser?
Solution 1:[1]
Example from Android launch Twitter intent .
The key lies in URI schemes.
Intent intent = null;
try {
// get the Twitter app if possible
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
// no Twitter app, revert to browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERID_OR_PROFILENAME"));
}
this.startActivity(intent);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arunkumar Maniam Rajan |
