Created
February 5, 2015 00:42
-
-
Save patrickhammond/d009769bcd36ed22ebcd to your computer and use it in GitHub Desktop.
Utility method to perform a runtime check that an app has been granted a permission.
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 static void checkHasPermission(Context contxt, String permissionName) { | |
String packageName = context.getPackageName(); | |
PackageManager packageManager = context.getPackageManager(); | |
int permissionStatus = packageManager.checkPermission(permissionName, packageName); | |
if (permissionStatus != PackageManager.PERMISSION_GRANTED) { | |
throw new SecurityException("Application requires <uses-permission android:name=\"" + permissionName + "\" />"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment