Android开发之手机铃声代码实现
时间:2014-05-06 22:55:52
收藏:0
阅读:500
- //设置--铃声的具体方法
- 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------闹铃音");
- }
评论(0)