Forum Xamarin.Android

How to retrieve Uri from RingtoneManager.ActionRingtonePicker (Ringtone Picker)

I' ve bind that function
public void RingtonePicker()

        Intent intent = new Intent(RingtoneManager.ActionRingtonePicker);
        intent.PutExtra(RingtoneManager.ExtraRingtoneTitle, "Select ringtone for notifications:");
        intent.PutExtra(RingtoneManager.ExtraRingtoneShowSilent, false);
        intent.PutExtra(RingtoneManager.ExtraRingtoneShowDefault, true);
        intent.PutExtra(RingtoneManager.ExtraRingtoneExistingUri, RingtoneManager.GetDefaultUri(RingtoneType.Alarm));
        ((Activity)Forms.Context).StartActivityForResult(intent, 0);

to a button that correctly open the ringtone picker but when i try to retrieve data from the OnActivityResult method the type of "intent.GetParcelableExtra(RingtoneManager.ExtraRingtonePickedUri);" is Java.Lang.Object and i'm not able to covert it to Uri, how can i get choosen uri from the ringtone picker? Here's my OnActivityResult function

protected void OnActivityResult(int requestCode, Result resultCode, Intent intent)
if (resultCode == Result.Ok)
switch (requestCode)
case 1:
Java.Lang.Object ringtoneJLO = intent.GetParcelableExtra(RingtoneManager.ExtraRingtonePickedUri);
Uri ringtone = (Uri)ringtoneJLO;



  • I think maybe this way:

    Uri ringtone = new Uri(ringtoneJLO.ToString());


  • EnricoBarbieriEnricoBarbieri USMember

    The "Uri" that you' re using is "System.Uri" that's different from "Android.Net.Uri" that's the type needed in the RingtoneManager.ExtraRingtoneExistingUri setting, i've solved the issue by converting the java lang object to an Android.Net.Uri:
    Android.Net.Uri ring = (Android.Net.Uri)intent.GetParcelableExtra(RingtoneManager.ExtraRingtonePickedUri);
    After that i can easly use it

Sign In or Register to comment.