Reputation: 2854
As far I know, to set a sound as ringtone it should be inserted in MediaStore. And for writing in MediaStore, WRITE_EXTERNAL_STORAGE permission is required. But... is there a way to set a sound (a MP3 file in external storage, for example) as ringtone without requiring WRITE_EXTERNAL_STORAGE permission?
Upvotes: 1
Views: 529
Reputation: 8695
You should use Android's RingtoneManager
. There is a method called [setActualDefaultRingtoneUri](http://developer.android.com/reference/android/media/RingtoneManager.html#setActualDefaultRingtoneUri(android.content.Context, int, android.net.Uri)):
public static void setActualDefaultRingtoneUri (Context context, int type, Uri ringtoneUri)
Sets the Uri of the default sound for a given sound type.
Parameters
- context: a context used for querying.
- type: the type whose default sound should be set. One of
TYPE_RINGTONE
,TYPE_NOTIFICATION
, orTYPE_ALARM
- ringtoneUri: a Uri pointing to the default sound to set.
You can get the Uri of a file by using File.toURI()
.
Upvotes: 1