- //设置--铃声的具体方法
- public void setMyRingtone(String path)
- {
- File sdfile = new File(path);
- ContentValues values = new ContentValues();
- values.put(MediaStore.MediaColumns.DATA, sdfile.getAbsolutePath());
- values.put(MediaStore.MediaColumns.TITLE, sdfile.getName());
- values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
- 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);
- Uri uri = MediaStore.Audio.Media.getContentUriForPath(sdfile.getAbsolutePath());
- Uri newUri = this.getContentResolver().insert(uri, values);
- RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, newUri);
- Toast.makeText( getApplicationContext (),"设置来电铃声成功!", Toast.LENGTH_SHORT ).show();
- System.out.println("setMyRingtone()-----铃声");
- }
- //设置--提示音的具体实现方法
- public void setMyNotification(String path)
- {
- File sdfile = new File(path);
- ContentValues values = new ContentValues();
- values.put(MediaStore.MediaColumns.DATA, sdfile.getAbsolutePath());
- values.put(MediaStore.MediaColumns.TITLE, sdfile.getName());
- values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
- values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
- values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
- values.put(MediaStore.Audio.Media.IS_ALARM, false);
- values.put(MediaStore.Audio.Media.IS_MUSIC, false);
- Uri uri = MediaStore.Audio.Media.getContentUriForPath(sdfile.getAbsolutePath());
- Uri newUri = this.getContentResolver().insert(uri, values);
- RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION, newUri);
- Toast.makeText( getApplicationContext (),"设置通知铃声成功!", Toast.LENGTH_SHORT ).show();
- System.out.println("setMyNOTIFICATION-----提示音");
- }
- //设置--闹铃音的具体实现方法
- public void setMyAlarm(String path)
- {
- File sdfile = new File(path);
- ContentValues values = new ContentValues();
- values.put(MediaStore.MediaColumns.DATA, sdfile.getAbsolutePath());
- values.put(MediaStore.MediaColumns.TITLE, sdfile.getName());
- values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
- values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
- values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
- values.put(MediaStore.Audio.Media.IS_ALARM, true);
- values.put(MediaStore.Audio.Media.IS_MUSIC, false);
- Uri uri = MediaStore.Audio.Media.getContentUriForPath(sdfile.getAbsolutePath());
- Uri newUri = this.getContentResolver().insert(uri, values);
- RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM, newUri);
- Toast.makeText( getApplicationContext (),"设置闹钟铃声成功!", Toast.LENGTH_SHORT ).show();
- System.out.println("setMyNOTIFICATION------闹铃音");
- }
Android开发之手机铃声代码实现,布布扣,bubuko.com
原文:http://blog.csdn.net/lsong89/article/details/25143403