Created
January 26, 2016 18:45
-
-
Save andreban/1780525015f6449867a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Set<String> getNativeAppPackage(Context context, Uri uri) { | |
PackageManager pm = context.getPackageManager(); | |
//Get all Apps that resolve a generic url | |
Intent browserActivityIntent | |
= new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); | |
Set<String> genericResolvedList | |
= extractPackagenames(pm.queryIntentActivities(browserActivityIntent, 0)); | |
//Get all apps that resolve the specific Url | |
Intent specializedActivityIntent = new Intent(Intent.ACTION_VIEW, uri); | |
Set<String> resolvedSpecializedList | |
= extractPackagenames(pm.queryIntentActivities(specializedActivityIntent, 0)); | |
//Keep only the Urls that resolve the specific, but not the generic urls | |
resolvedSpecializedList.removeAll(genericResolvedList); | |
return resolvedSpecializedList; | |
} | |
public static Set<String> extractPackagenames(List<ResolveInfo> resolveInfos) { | |
Set<String> packageNameSet = new HashSet<>(); | |
for (ResolveInfo ri: resolveInfos) { | |
packageNameSet.add(ri.activityInfo.packageName); | |
} | |
return packageNameSet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment