简体   繁体   中英

(Android 11) How do I allow an app to access a file in another app's Android/data folder?

I have two apps. One app (P) consumes a file with a proprietary extension (say.XXX) and a.json file with instructions for what P will be doing with that other file. The other app (Q) creates those files and intents to P, telling P the path to the.json file, which contains the path to the.XXX file. P then reads the.json file (in Q's directory) and then reads the.XXX file (again, in Q's directory). P does a lot of stuff with the.XXX file, but I don't believe P has to write to it.

Prior to Android 11, all the files were just in root/MyAppDirectory_Q and it was easy to access/share files between apps. With scoped storage getting more popular, I need to keep all files in the Android/data/com.companyName.MyApp_Q directory.

How do I intent from Q to P and give P the permissions to access the two files in Q's Android/data folder? I'm doing this in Xamarin, but I'll eventually have to recreate Q in straight Java once it's working.

One approach is for Q to send a broadcast to P with URIs in the Intent (using ClipData). Q will grant persistable permission using FLAG_GRANT_PERSISTABLE_URI_PERMISSION and grantUriPermission() . P will receive the broadcast with the URIs and accept them using takePersistableUriPermission() . After that, P will be able to access the files using the URIs provided. The URIs may come from FileProvider, so they are backed by the files in Q's external files directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM