rDroid rDroid - 5 months ago 48
Android Question

Is there a way to check for manifest permission from code?

How do I check for a specific permission in the manifest.xml from code? I want to throw some exception if some permissions that are necessay for my application are missing. for example

I know that android will also throw an exception on the launch of the specific activiy that is using GPS, but I need to check the manifest and throw an exception at the launch of the application itself. This holds not only for location access, but also for other permissions. Any suggestions would be helpful.

aNi aNi

You can check whether the permission is granted or not for specific permission by using PackageManager. For example

    PackageManager pm = getPackageManager();
    if (pm.checkPermission(permission.FINE_LOCATION, getPackageName()) == PackageManager.PERMISSION_GRANTED) {
        // do something
    } else {
        // do something