Last active
October 13, 2023 18:54
-
-
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.
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
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More
Check https://stackoverflow.com/a/41992932/3503855 for more details.