0

I found similar questions here and here. For some reason, all the options I found worked only with EXTERNAL_CONTENT_URI.

I used based on its approach and it works for me if I use EXTERNAL_CONTENT_URI. But if I need to get the sounds from INTERNAL_CONTENT_URI I can't make choice in related application, which has opened by startActivityForResult. The app works like readonly.

Is there any way to make choice from INTERNAL_CONTENT_URI? May be, I need some permissions?

My code adapted for Xamarin:

        const int REQ_PICK_AUDIO = 1;          
        Intent audio_picker_intent = new Intent(
            Intent.ActionPick, 
            Android.Provider.MediaStore.Audio.Media.InternalContentUri); // with ExternalContentUri it works
        XxmsApp.Droid.MainActivity.Instance.StartActivityForResult(audio_picker_intent, REQ_PICK_AUDIO);
  • @LeoZhu-MSFT, yes. You're right, it works. Thanks! But I find its no user-friendly, because the such behavior is not obvious for some users – Александр May 18 '20 at 16:03

1 Answers1

1

You could get the content uri of the sounds which in the internal storage by INTERNAL_CONTENT_URI.

The codes above should work fine.You could get the sounds uri in the OnActivityResult method.

In your MainActivity over write the method :

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);
        if (requestCode == 1)
        {
            var path = data.Data;  // you could get the sound uri.(e.g: content://media/external/audio/media/113)
        }
    }

PS:

I test on Android 10.0 emulator,when the Intent.ActionPick open the list,it doesn't seem to work when I select the sound, but when I click OK, it actually returns the Uri of the sound.

Like below:

enter image description here

Leo Zhu
  • 15,726
  • 1
  • 7
  • 23