Android Question Using Photos from the Phone

Shadow&Max

Active Member
Licensed User
Longtime User
OK, so I want to retrieve a photo from the phone... I use the ContentChooser to get the photo.

Now, I want to save the location of that picture in a file, and reload it at a later time.

I can GET the picture the first time... That's working. Then I save the Dir and FileName to variables that are saved in the file.

When I reload the file, I want to set an image control to that photo.

I'm getting a Security message when I try to access that file again:
java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{429c19b0 13253:com.twodogapps.gaa/u0a136} (pid=13253, uid=10136) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS

The file dir and file name that are being saved are:
Dir: ContentDir
FileName: content://com.android.providers.media.documents/document/image%3A131

The ContentChooser is initialized, I'm pretty sure. I set the image like this:

iv.SetBackgroundImage(LoadBitmap(gs.listhere(Index).PhotoDir, gs.listhere(Index).PhotoFile))

In the above line, the index is correct and is getting the values above. As soon as it hits this line, I get the SecurityException shown above.

What am I doing wrong here?

Also, on my phone's permissions for the app it says:

  1. Modify or delete the contents of your USB storage
  2. full network access
  3. access Bluetooth settings - Pair with Bluetooth devices
  4. read the contents of your USB storage.
As far as I can tell those are all I need in terms of permissions.

I don't want to save the file in my apps database because they're just too big and no need to waste duplicate space.
 
Last edited:

Shadow&Max

Active Member
Licensed User
Longtime User
is your kitkat 4.4? Mine is 4.4 and this permission thing is a royal pain in the butt...
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
so far ALL kitkat is 4.4 ;)
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
ok, wasn't sure. Thanks... Problem still exists lol!
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Indeed it does, if you would like me to test a project on nexus 7 I can. That way you will know if it only certain devices. Probably won't have time now though until tomorrow evening. Probably not much use to you, sorry. But if your still in the same position tomorrow.....

Good luck
 
Upvote 0

Shadow&Max

Active Member
Licensed User
Longtime User
Thanx Barx! Na, that's not necessary. I'm doing a workaround of my own and restoring the pictures in the internal storage, then nuke them when I don't need them. Finding out that it works on the Nexus 7 doesn't help with every other device that's out there, but I really appreciate the offer...
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Do you have a example project I could load and run?
 
Upvote 0

Gregg Homan

Member
Licensed User
Longtime User
Erel,

I totally overlooked your post #28. For some strange reason I never got alerted that this thread was updated after my last post#20 so I failed to realize that posts #21-28 existed until just now as I write. Thanks for the above fix though I did come to realize that the workaround discussed in post #9 above actually worked quite well for I was able use the temporary work directory to re-size the images being processed by my app.

Thanks,
Gregg
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I post my question here since I think it is related to this thread.

My app is picking images from the gallery using ACTION_PICK intent and then decoding the result with GetPathFromContentResult It works fine for gallery folder and also, for instance, for "whatsapp images" folder and others


But on some devices, the returned string when picking from the gallery (from other folders it still works) is

B4X:
(AIRPLANE MODE OFF) --> here it crashes ( GetPathFromContentResult returns null)

content://com.google.android.apps.photos.content/0/https%3A%2F%2Flh6.googleusercontent.com%2Fy8zxYXsru....(a large string which changes each time)



B4X:
(AIRPLANE MODE ON) --> here it works (GetPathfromcontentresult returns "/storage/sdcard0/DCIM/Camera/..."

content://media/external/images/media/3198...


It seems to be as if, even if the picture is in the device, it is referenced as a server link. I have no idea at all

Anyone has found this? Any workaround?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
It is a picture that is stored in the same device.

I do this in my camera app. The user chooses a picture from the gallery (using intent.ACTION_PICK). Then, on Activity_OnResult, the app tries to get the path using GetPathFromContentResult, copies it to a temporary folder and let the user edit this new copy.

But I was reported that on some phones (SGIII mini, for instance) it didn't work, and finally found the why. But not the solution. Seems like when you are online, the result is different than when you are with no network.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Yes, I am using the latest version.

So you mean that in my case I can use the above code? But I don't know the Dir and Filename valies to use for File.OpenInput(..)
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
You mean I need to use ContentChooser? I was using intent.ACTION_PICK, but will try with it

Thanks!
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Now it works ok ;) In fact I had already used ContentChooser, but don't know why decided to try with intents
 
Upvote 0
Top