插入一个铃声ringstone

ContentValues values = new ContentValues(); 
values.put(MediaStore.MediaColumns.DATA, <<asbolutePathToYourAudioFileHere>>); 
values.put(MediaStore.MediaColumns.TITLE, "<<yourRingToneNameHere>>"); 
values.put(MediaStore.MediaColumns.SIZE, k); 
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg");    // assuming it's an mpeg, of course 
values.put(MediaStore.Audio.Media.ARTIST, "<<yourArtistNameHere>>"); 
// values.put(MediaStore.Audio.Media.DURATION, duration);  // doesn't appear to be necessary if you don't know 
values.put(MediaStore.Audio.Media.IS_RINGTONE, true); 
 
Uri uri = MediaStore.Audio.Media.getContentUriForPath(outPath);   
Uri newUri = getContentResolver().insert(uri, values); 
 
RingtoneManager.setActualDefaultRingtoneUri( 
                                <<MyActivity>>.this, 
                                RingtoneManager.TYPE_RINGTONE, 
                                newUri); 

 

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 
); 

 

你可能感兴趣的:(one)