Android Question Content Chooser - Crashes on multiple phones.

Pawan_91

New Member
Hi All,

This is my first post on B4A-Android, as till now I got resolution's for all my issues in the forum.
However, its been 1week now, I have been looking for the solution on the Content Chooser crash issue.

Code snippet to copy chosen file to "audio.mp3" :-

B4X:
Sub Process_Globals
Dim uploadFolder As String
Dim rp as RuntimePermissions
End Sub

Sub Activity_Create(FirstTime As Boolean)
uploadFolder = rp.GetSafeDirDefaultExternal("uploads")
CC.Show("audio/mpeg", "Choose audio file")
End Sub

Sub CC_Result (Success As Boolean, Dir As String, FileName As String)
   
    If Success = True Then
        File.Copy(Dir,FileName,uploadFolder,"audio.mp3")
    Else
        ToastMessageShow("No File Selected",True)
    End If  
   
End Sub

Manifest

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)

Below crashes are logged for ContentChooser_Result on different devices.

1.Fatal Exception: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media/113228 from pid=19038, uid=10267 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission().

2.Fatal Exception: java.lang.SecurityException: com.venir.destem has no access to content://media/external/audio/media/143

3.Fatal Exception: java.io.FileNotFoundException: Can't access /storage/0000-0000/Dunsin-Oyekan-Fragrance-To-Fire.mp3

4.Fatal Exception: java.io.FileNotFoundException: /storage/emulated/0/Music/Asylzhan Abdulla - Ұнайсың.mp3: open failed: EACCES (Permission denied)


Note:- On some devices it works fine even with the sdcard/external file chosen.

Any idea what could be the reason behind this crashes?
 

Alexander Stolte

Expert
Licensed User
Longtime User
1.Fatal Exception: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media/113228 from pid=19038, uid=10267 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission().

2.Fatal Exception: java.lang.SecurityException: com.venir.destem has no access to content://media/external/audio/media/143

3.Fatal Exception: java.io.FileNotFoundException: Can't access /storage/0000-0000/Dunsin-Oyekan-Fragrance-To-Fire.mp3

4.Fatal Exception: java.io.FileNotFoundException: /storage/emulated/0/Music/Asylzhan Abdulla - Ұнайсың.mp3: open failed: EACCES (Permission denied)
add this to the Manifest:
B4X:
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
 
Upvote 0

Pawan_91

New Member
I've also encountered this issue with one device. It seems like a bug in the third party app. It doesn't grant the permission properly.
You don't need any permission to access the resource returned by ContentChooser.

You can add Try / Catch to catch this error.

Thanks for the quick feedback.

However, I would like to know what could be the possible work arounds after I catch the error in catch block.
As my app is already on app store and this issue is impacting badly more than 70% of devices 😢😢
 
Upvote 0

Pawan_91

New Member
add this to the Manifest:
B4X:
SetApplicationAttribute(android:requestLegacyExternalStorage, true)

Thanks for the quick response.

Will try this , however, I don't know whether it works or not because on my all local devices it is working fine.
So I can only get confirmation, once I rollout the update on play store.
 
Upvote 0
Top