Created
November 6, 2017 20:05
-
-
Save andreban/237fd93ca98818b6af5a32e9e2afef98 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 boolean hasOficialPackage() { | |
Intent intent = new Intent("..."); | |
PackageManager pm = getPackageManager(); | |
// Queries for Packages that can handle a given Intent | |
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(intent, 0); | |
for (ResolveInfo ri: resolvedActivityList) { | |
// Is this the package we'e looking for? | |
if (ri.activityInfo.packageName.equals("my.package.name")) { | |
try { | |
// This is the package we want. Retrieve signatures! | |
PackageInfo pi = pm.getPackageInfo(ri.activityInfo.packageName, PackageManager.GET_SIGNATURES); | |
for (Signature signature : pi.signatures) { | |
// Should validate the signature correctly. Using this for the sake of brevity. | |
if (signature.toString().equals("expected_sig")) { | |
return true; | |
} | |
} | |
} catch (PackageManager.NameNotFoundException ex) { | |
// Shouldn't happen, as we've just retrieved the name from PackageManager. | |
// Log the error, and continue looking. | |
Log.d("MyActivity", "Package " + ri.activityInfo.packageName + "not found"); | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment