Android Question move user selected file to app internal files dir

giggetto71

Active Member
Licensed User
Longtime User
Hi guys,
what is the best way to move (copy) an user selected file in the app internal dir?
the file is an audio file that I will need to play later as a custom alarm file.
thanks
 

giggetto71

Active Member
Licensed User
Longtime User
I am sorry..I was too quick and that resulted in a stupid question..I guess I was just looking for a solution to avoid the crazyness I am facing for all the weekend trying to get the permission for my app to play external storage mp3 files. but clearly also copying requires permission..
let me try to explain better what I am trying to do:

- user chooses the sound he wants to be played in some conditions by the app. to allow user to choose the sound I have used the ShowRingtonePicker("rm", rm.TYPE_ALARM,"")
- if the users selects one of the "system" default sound, then I am able to play it anytime without issues using the media player
- if the users selects one sound that has been added from the SD (which is shown in the ringtone picker) then I get a

java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media/13620 from pid=27735, uid=10341 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

I have tried to add

AddPermission(android.permission.READ_EXTERNAL_STORAGE) to the manifest

but it did not help.
any idea?
 
Upvote 0

KZero

Active Member
Licensed User
Longtime User
I am sorry..I was too quick and that resulted in a stupid question..I guess I was just looking for a solution to avoid the crazyness I am facing for all the weekend trying to get the permission for my app to play external storage mp3 files. but clearly also copying requires permission..
let me try to explain better what I am trying to do:

- user chooses the sound he wants to be played in some conditions by the app. to allow user to choose the sound I have used the ShowRingtonePicker("rm", rm.TYPE_ALARM,"")
- if the users selects one of the "system" default sound, then I am able to play it anytime without issues using the media player
- if the users selects one sound that has been added from the SD (which is shown in the ringtone picker) then I get a

java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media/13620 from pid=27735, uid=10341 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

I have tried to add

AddPermission(android.permission.READ_EXTERNAL_STORAGE) to the manifest

but it did not help.
any idea?


-you should use runtime permissions
 
Upvote 0

giggetto71

Active Member
Licensed User
Longtime User
got it. works now.
I have added the runtime permission AND the add permission to the manifest.
thanks!

B4X:
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result = False Then Return

    
    
    Dim mp As MediaPlayer
    Log(GlobalUri)
    
    mp.Initialize
    mp.Load(rm.GetContentDir, GlobalUri)
    mp.Play
    ......
 
Upvote 0

saeed10051

Active Member
Licensed User
Longtime User
hi what is rm in this case. I am also looking for a way to selet external csv file and then loading it in my app. can you please post zip fle of code over here
 
Upvote 0
Top