Skip to content

Instantly share code, notes, and snippets.

@AnixPasBesoin
Last active October 13, 2023 18:54
Show Gist options
  • Save AnixPasBesoin/431cab2a9945a14cb009309719d0f828 to your computer and use it in GitHub Desktop.
Save AnixPasBesoin/431cab2a9945a14cb009309719d0f828 to your computer and use it in GitHub Desktop.
A utility class that allows retrieving android permissions used in the manifest file.
import android.content.Context;
import android.content.pm.PackageManager;
public final class PermissionUtils {
private PermissionUtils() {
// no-op
}
/**
* Retrieves permissions listed in the manifest file
* @param context Context
* @return Returns String array of permissions
*/
public static String[] retrievePermissions(Context context) {
try {
return context
.getPackageManager()
.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS)
.requestedPermissions;
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException("This should have never happened.", e);
}
}
}
@AnixPasBesoin
Copy link
Author

More

Check https://stackoverflow.com/a/41992932/3503855 for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment