Office Hours Transcript: 2021-08-19

Kai_H joined

Hello

kai_h2 joined

 

Kai_H left

Trying the beta now :)

 

hi, Kai!

 

sorry for the delay

np

I’m multitasking, and this task had been pre-empted

 

how can I help you today?

:*(

 

I wanted to share some pictures with my app today and it told me that it doesn’t have access to the file system.

 

Huh

 

My text was deleted before I could send it.

 

Anyway, I found the following in my Manifest:
<!-- Read files from sdcard --> <!-- TICKET-123 Permission not needed anymore starting with API 30 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="30"/>

 

I think I’ve misunderstood "READ_EXTERNAL_STORAGE" in Android 11/API 30.

they made a mess out of all of this, and I’m not sure I understand it myself anymore

Could you please clarify for me when and how it is needed going forward from API 30

 

Uh

 

If YOU don’t understand it anymore, I wonder who still does…

I have largely given up on trying to have some holistic view of all of this – at this juncture, I focus on specific problems

 

so… where is this file that you are trying to share, and how did you get the path to the file?

I was in the gallery on an emulator for API 30, selected two pictures, "share with" and then selected my app.

that should have triggered ACTION_SEND_MULTIPLE, where you would get two content Uri values, one per picture

 

if my analysis is correct, how are you using those Uri values?

Uh… looks at code

 

mData.getParcelableArrayList(Intent.EXTRA_STREAM);

so, that gives you the Uri objects themselves — are you sharing them yourself via ACTION_SEND_MULTIPLE? or what are you doing with the Uri objects, once you have them, that is leading to this error?

This is done in the "onCreate" of a "HandleFilesActivity". We put them in a variable called "list" and then then return from "onCreate" to… I have no idea :)

That does not give me a lot to go on. Ideally, you would just share those Uri values. IOW, if you are accepting Uri objects from outside and sending Uri objects back to the outside, your app should have no need to ever read the content pointed to by those Uri values, and permissions should not come into play.

Why should it have no need to read the content?

 

Yes, it’s sparse. I’m still tring to understand the code. It’s undocumented

Think of a desktop OS. If you drag-and-drop some file from a desktop file manager (File Explorer, Finder, Nautilus, etc.) into some program, the file manager does not need to read the content of the file.

Yes, but we eventually wanna do that, as we upload things to a server and whatnot.

 

Which is another, later step.

And that’s fine. Make sure that you are either only using those Uri objects in the misnamed HandleFilesActivity, or you pass them along to other activities carefully and with the correct flags: https://commonsware.com/blog/2020/08/08/uri-access-lifetime-still-shorter-than-you-might-think.html

 

and, reading the content from those Uri objects should never involve the filesystem, so you should not get an error related to filesystem permissions

 

for uploading to a server, there are recipes for doing that using just a Uri: https://commonsware.com/blog/2020/07/05/multipart-upload-okttp-uri.html

I just found this gem:
// check for file access
if (!AndroidUtils.hasPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE))

 

Which might be the solution to my mystery

OK, that checks to see if you have that permission, presumably

 

but, you know where you are getting the Uri objects initially, and you know where your code is crashing

 

you need to trace through your code to understand how you are getting from Point A to Point B

 

and, you need to determine why you are doing any filesystem operations here, because so far, I haven’t heard anything that should involve the filesystem

Those come later. I assumed they came in this step, but apparently it’s just a literal check for the permission

 

Which I didn’t expect

 

Tbh, I came here because I knew my understanding of READ_EXTERNAL_STORAGE is lacking. I didn’t look into the code beforehand.

 

And I didn’t expect it was so foobared that even you couldn’t give holistic advice anymore. Damn.

unfortunately, I have been rather "heads down" for the past 1.5 years and haven’t been fussing with a lot outside of what I need to

 

so, I am rusty on the issue

Ok. What did you do instead?

um, I have been helping a consulting client

 

their app does not presently have the need to read content from the device, which means I haven’t been working on this specific area that is causing you grief

If I remove that check, it works flawlessly, at least for my test case.

 

I am gonna create a ticket and bugger my boss…

 

I have another question about Accounts on Android. I don’t really get how they are secured and if App "Oscar" can access the Account data of App "Mathilde" or not.

I have avoided AccountManager throughout my Android career, so I cannot really comment upon it

I think I have asked about this before and got a similar answer :)

 

But it was worth a shot

early on, it was not very well documented and seemed extremely opinionated in its implmentation

 

I am uncertain that it got much better

 

and I can’t remember the last app that I encountered that used it, though I’m not a big consumer of apps that need accounts

Ok

 

Thanks for your answers

sorry I could not be of more direct assistance today

That’s ok

 

It’s good to have someone to talk technical about and ask questions.

I’m happy to help!

 

that’s a wrap for today’s chat — the next one is Saturday in the 4pm US Eastern time slot

 

have a pleasant day!