Skip to content Skip to sidebar Skip to footer

Android 11: Primary Directory (invalid) Not Allowed For Content://media/external/file Allowed Directories Are [download, Documents]

I am trying to create PDF file from base64 string. Because of Storage Update in Android 11, I have to change my code but I'm getting following error in Android 11 devices: java.lan

Solution 1:

I finally found a solution. I can't say it's a best solution but it works perfectly.

folderPath = mContext.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS) + File.separator + "appFolderName";

to

folderPath = mContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + File.separator + "appFolderName";

I suppose in Android 11, they allowed to create folder/file in DOWNLOADS folder but not DOCUMENTS. Best regards.

Note for Huawei Developers: You just keep the current file writing strategy. No need to Android 11 special code for now. I tried the new file writing method and it crashed. Apperantly, they didn't fully implemented Android 11.

Post a Comment for "Android 11: Primary Directory (invalid) Not Allowed For Content://media/external/file Allowed Directories Are [download, Documents]"