• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Permission Denied - android.permission.MANAGE_DOCUMENTS

RawrJoel

Newbie
Hey all. I'm new here, hoping to learn a lot from these forums and hopefully get some help should I need it, and even provide it if I can.

So I'm making just a play application (my first one - something small). But I have a problem.
It's a contact application (manages contacts within the application only so far) you can set an image, and whenever you load the contact list, it displays that. If the user adds a new contact, with an image, then goes to view contacts, the image shows.

If they add the user, then close the application process, then re-open it, the image is blank and i get the error:
Code:
java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{2a33f682 31420:com.joelmale.android.contactmanager/u0a60} (pid=31420, uid=10060) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS

I've researched this a lot, heard a lot about perm permissions, kitkat, but I really feel like they don't apply to me and wouldn't even have a clue on how to integrate the solutions into my code.

My code is here: http://pastebin.com/UU7QU0rV

I have 4 classes (including this one) - Contact (simple object of a contact, holds the URI, name, etc). Database (Handles all of the database stuff, so when creating a new contact its added there, and then every time the app boots it loads all contacts from the database, this also stores the URI for the image), then EditContact (which is what im working on right now, but works fine).

At line 306 I try to set up the image with the contacts image, this throws the permission denied and thus the image is blank.

However, if the user adds a contact with the exact same image, (or edits a contact and changes their image) then the contact with the same image (but blank because of permission) will then show the image in the program.

Can someone tell me how to fix this error? I've tried adding permissions to my manifest, but it does nothing.
 
Welcome to our AndroidForums, Joel! :)

Try doing a Google search with this string:

"java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS"

(i.e,. omitting your app's details, etc. so we get a wider set of results)

The first link reported might be helpful:

http://stackoverflow.com/questions/...exception-when-trying-to-read-from-mediastore

P.S. stackoverflow.com is an awesome resource for you--highly recommended!

Cheers and best of luck!
 
Hi Scary Alien!

I have tried doing that google search however the replies on those stackoverflows posts aren't what my problem is.

As your's lists KitKat, which I don't think I am using.
And the answers list a problem with his app being able to select an image from the gallery, mine can already do that. Just upon closing/opening, it does not load the image as it gets this error :(
 
I'm hoping / guessing the version of Android shouldn't make a difference...

I can't view your pastebin from here at work, but I'll try to take a peek at things this evening after I get home...are you using the Eclipse IDE (and if so, can you post-up an export of the project)?
 
I'm hoping / guessing the version of Android shouldn't make a difference...

I can't view your pastebin from here at work, but I'll try to take a peek at things this evening after I get home...are you using the Eclipse IDE (and if so, can you post-up an export of the project)?

Hi scary, I am using android studio currently. And I'm not at my computer anymore as I'm just about to go to bed. But first thing in the morning I can post my project.

I've tried a few things like dataFlags (as per the SDK API website) and using persis permissions, but had very little luck getting the right syntax.

Thanks again!
 
Thanks! I'll switch gears and look at this in a second (been busy trying to get the Android M developer preview installed on my Nexus 5 (not going well, LOL, and ready for a mental break :p).

BRB.
 
Ah! I saw something about that in my SDK manager. I'm very new to Android SDK however pretty comfortable in Java. It's quite confusing having to deal with permissions and layouts and stuff :<
 
Okay, I've got the Android Studio installed, but it's an older version and have only barely used it (I'm still using Eclipse as my main IDE), so I'm not current on importing your setup into the Android Studio.

But I do have a couple of questions / suggestions:

1. What is your API level set to for your project?

2. Have you tried adding the "android.permission.READ_EXTERNAL_STORAGE" permission? (the Manifest permission page says "This permission is enforced starting in API level 19. Before API level 19, this permission is not enforced and all apps still have access to read from external storage.", so if your API level is set less than 19, then I'm guessing you might need this).
 
Hi again!

1. My Min API level is 9, target is 22, compile is 22.

2. I have no tried adding that, I just have the WRITE_EXTERNAL_STORAGE one. I can add it and give it a go, but from the sort of the stuff I've read on Stackoverflow, I don't think adding a permission can fix this and that it's more about giving persistant permissions or something.
 
Currently have a gradle bug or something :( can't run my project until I sort it out.
Will try to fix this ASAP and try that permission.
 
Ah, no worries, Joel :).

I've been re-reading the original stackoverflow link I sent you above as well as this one:

http://stackoverflow.com/questions/20248178/kitkat-error-while-trying-to-load-an-image

it really seems like it's the security/permissions of the Uri that you're using from the changes that were indeed introduced in KitKat.

The suggested solution from that link just above of adding this code to your MainActivity sounds like it might work:

Code:
Intent intent;

        if (Build.VERSION.SDK_INT < 19){
                                intent = new Intent();
                                intent.setAction(Intent.ACTION_GET_CONTENT);
                                intent.setType("image/*");
                                startActivityForResult(intent, KITKAT_VALUE);
                            } else {
                                intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                                intent.addCategory(Intent.CATEGORY_OPENABLE);
                                intent.setType("image/*");
                                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
     }
  }
}

which is also very similar to the first solution proposed in the first stackoverflow link:

Had the same problem for the last couple of days. Tried a few solutions, but for some reason I was getting permission denial on Uri content provider for some images even when I had the android.permission.MANAGE_DOCUMENTS permission added to my manifest.

Here's a workaround, for the time being:

Code:
i =newIntent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, CHOOSE_IMAGE);

This forces the older image gallery to open instead of the new Kitkat documents view.

Now, you can get the Uri by calling the following in your onActivityResult:

Code:
Uri selectedImageURI = data.getData();
 
Yes, i saw this post, and do believe it may also work for me, but i'm not sure where to do the above functions in my class.
 
Oh, happy to help! :)

BTW, you mean adding the android.permission.READ_EXTERNAL_STORAGE was all you needed (not the other stuff)?

Either way, very glad you've got it working! :)
 
Back
Top Bottom