Android Question TargerSDK 29 (Android 10.0) - Suggestion about show files in Gallery and File Provider??

tuhatinhvn

Active Member
Licensed User
Longtime User
Since 8/2020 any new apps must set target SDK to 29, many changes Android developer need update, short solution is use
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
but this is not good solution because in SDK 30 , this attribute will be bypass and will be error!!!

These are some issues i met when update app to targetSDK 29:
1. With old target SDK <29 we can use this code to add file to gallery https://www.b4x.com/android/forum/threads/show-image-in-gallery-android-7-0.97662/#content
But with new target SDK , this code can not work
(You can try with target SDK =29 and use file-provider https://www.b4x.com/android/forum/t...om-your-app-with-file-provider.70458/#content)
I search on Stackoverflow , their solution here :
https://stackoverflow.com/questions/57923329/save-and-insert-video-to-gallery-on-android-10
How can we implement this code to B4A?

2. And about File-provider

B4X:
Public Sub Initialize
    Dim p As Phone
    If p.SdkVersion >= 24 Or File.ExternalWritable = False Then
        UseFileProvider = True
        SharedFolder = File.Combine(File.DirInternal, "shared")
        File.MakeDir("", SharedFolder)
    Else
        UseFileProvider = False
        SharedFolder = rp.GetSafeDirDefaultExternal("shared")
    End If
    Log($"Using FileProvider? ${UseFileProvider}"$)
End Sub

I think
B4X:
SharedFolder = File.Combine(File.DirInternal, "shared")
should use
B4X:
SharedFolder = rp.GetSafeDirDefaultExternal("shared")
as default value, because this folder will be visible when use file manager app on Android 10, File.DirInternal will be invisible on phone without root, if we want to users can use files without using our app to open it!

Thank for reading , please suggestion any solutions for it!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
but this is not good solution because in SDK 30 , this attribute will be bypass and will be error!!!
This will work for now, but you are correct that in the long run (next year) it is not a good solution.

2. No reason to change it. It is safer to use File.DirInternal. It has nothing to do with other apps opening your app files directly.

1. The MediaScannerConnection code should work with other folders. You can put the images in rp.GetSafeDirDefaultExternal.
 
Upvote 0

Omar Parra A.

Expert
Licensed User
Longtime User
??

Section: 29
For now there is a simple workaround:
 
Upvote 0
Top