Android RingtoneManager

File k = new File(path, "mysong.mp3"); // path is a file to /sdcard/media/ringtone

ContentValues values = new ContentValues();
values
.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values
.put(MediaStore.MediaColumns.TITLE, "My Song title");
values
.put(MediaStore.MediaColumns.SIZE, 215454);
values
.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values
.put(MediaStore.Audio.Media.ARTIST, "Madonna");
values
.put(MediaStore.Audio.Media.DURATION, 230);
values
.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values
.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values
.put(MediaStore.Audio.Media.IS_ALARM, false);
values
.put(MediaStore.Audio.Media.IS_MUSIC, false);

//Insert it into the database
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
Uri newUri = main.getContentResolver().insert(uri, values);

RingtoneManager.setActualDefaultRingtoneUri(
  myActivity
,
 
RingtoneManager.TYPE_RINGTONE,
  newUri
);
신고

Trackbacks 0 / Comments 0

티스토리 툴바