How to set ringtone in Android from my activity?

后端 未结 9 1484
一个人的身影
一个人的身影 2020-11-22 12:11

I\'m trying to find a way to set a new default ringtone by code from my Android activity.

I have already downloaded the ringtone into a bytearray.

9条回答
  •  醉酒成梦
    2020-11-22 12:49

    Answer By Vidar is too long and it adds duplicate entries every time you want to set a song as ringtone . Instead you should try this

    Uri newUri=Uri.parse("content://media/external/audio/media/"+ID);  
    try {
          RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri);
        }
    catch (Throwable t) {
    
    
                      }
    

提交回复
热议问题