Permission denial exception, even though correct permissions have been added to the Manifest?
Prior to Android Marshmallow, declaring the permissions in manifest was enough and system used to grant those permissions during installation. But starting from Android M declaring the permissions is not enough. The authority to grant the permission has been transferred to user. You need to request those permissions at runtime in order to allow users to grant the permissions.
Follow this official documentation for implementation details.
Android - java.lang.SecurityException: Permission Denial: starting Intent
You need to set android:exported="true"
in your AndroidManifest.xml
file where you declare this Activity
:
<activity
android:name="com.example.lib.MainActivity"
android:label="LibMain"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" >
</action>
</intent-filter>
</activity>
SecurityException: Permission Denial: While launching Activity via explicit intent
Using custom permissions is a fairly advanced thing to do in Android. The basic recipe is:
- Decide what you want the permission name to be. It needs to be unique on the device. So,
permission.SHARE_POST
is not a good choice — add a prefix that is tied to your domain name or whatever else it is that you are using as the basis for your apps'applicationId
values. - In the app that is defending itself with the permission, declare a
<permission>
element, with anandroid:name
attribute holding the permission name from step #1. Optionally, give it anandroid:protectionLevel
attribute (e.g.,signature
, so only apps signed by the same signing key can work together). - In the app that is defending itself with the permission, add an
android:permission
attribute on the component (e.g.,<activity>
), with a value of your permission name from step #1. - In the app that is looking to communicate with the app from step #3, add the
<uses-permission>
attribute, with anandroid:name
attribute holding the permission name from step #1. - In both apps, set your
minSdkVersion
to 21, as there are security problems with custom permissions on older versions.
This will work, if the defender (step #2 and #3) will always be installed before the client (step #4). If you want the apps to be installable in either order, replace step #2 from above with:
- In both apps, declare a
<permission>
element, with anandroid:name
attribute holding the permission name from step #1. Optionally, give it anandroid:protectionLevel
attribute (e.g.,signature
, so only apps signed by the same signing key can work together). Also, ensure that both apps are always signed by the same signing key, as otherwise they cannot both define the same permission.
Getting Permission Denial Exception
Please check these questions too:
Android KitKat securityException when trying to read from MediaStore
Permission denial: opening provider
For the same problem on KitKat, I used this. It's an option/workaround I had found from one of the Stack Overflow links, you will be able to select files from Downloads/Recent.
public static final int KITKAT_VALUE = 1002;
Intent intent;
if (Build.VERSION.SDK_INT < 19) {
intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, KITKAT_VALUE);
} else {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, KITKAT_VALUE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == KITKAT_VALUE ) {
if (resultCode == Activity.RESULT_OK) {
// do something here
}
}
}
Reference:
Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT
http://developer.android.com/guide/topics/providers/document-provider.html#client
Related Topics
How to Show and Hide Actionbar with Appcompat V.7
Continually Running Background Service
Sync Scrolling of Multiple Recyclerviews
Android, Move Bitmap Along a Path
Android L (API 21) - Java.Lang.Illegalargumentexception: Service Intent Must Be Explicit
Tab Not Taking Full Width on Tablet Device [Using Android.Support.Design.Widget.Tablayout]
Reusing Fragments in a Fragmentpageradapter
Monitor Network Activity in Android Phones
Get Battery Level Before Broadcast Receiver Responds for Intent.Action_Battery_Changed
Get Image from the Gallery and Show in Imageview
Surfacetexture's Onframeavailable() Method Always Called Too Late
Touch and Drag Image in Android
How Could I Filter the Listview Using Baseadapter
Android Volley Self Signed Https Trust Anchor for Certification Path Not Found
Value of a Global Variable Is Reset After It Is Initialised in Valueeventlistener
How to Record Screen and Take Screenshots, Using Android API
Android 4.3: How to Connect to Multiple Bluetooth Low Energy Devices