Android 11: How to access app specific files from Browser

72
November 29, 2021, at 2:00 PM

My app is creating some html files (reports) that user can open by using web browser.

But from Android 11 data storage privacy, the browser cannot read the html files from app private storage.

Storage Access Framework requires manual intervention.

Is there any workaround, so that web browser can access the generated html files from my app specific storage?

Answer 1

I am able to access this now by using Storage Access Framework (scoped storage), instead of using app private storage.

Reference: https://developer.android.com/training/data-storage/shared/documents-files

Use Intent: ACTION_OPEN_DOCUMENT_TREE to get the scoped storage permission. Then write the file into the storage:

try {
            ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "w");
            FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
            fileOutputStream.write(("Overwritten at " + System.currentTimeMillis() +
                    "\n").getBytes());
            // Let the document provider know you're done by closing the stream.
            fileOutputStream.close();
            pfd.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

These files can be accessed using browser intent.

READ ALSO
Intellij IDEA, java, maven, can´t use imported library [closed]

Intellij IDEA, java, maven, can´t use imported library [closed]

Want to improve this question? Add details and clarify the problem by editing this post

63
shap.DeepExplainer gives an error related to GlobalMaxPooling1D layer of CNN

shap.DeepExplainer gives an error related to GlobalMaxPooling1D layer of CNN

I am getting an error as below whenever I want to explain CNN classifier with SHAP for sentiment analysis:

55
How can I make a constraint so that the appointment cannot be repeated?

How can I make a constraint so that the appointment cannot be repeated?

I want to make a constraint so that the appointment with a certain doctor cannot be repeated more than onceFor example, if a person chooses an appointment on 11/09/2021 from 15:00 until 15:30, the same appointment cannot be booked again at the same doctor

79
How can I add individual html links into folium's popup window

How can I add individual html links into folium's popup window

I want to add individual html links of google search to the popups on a folium map according to the name of the street the icon is placed

39