我的问题是代码没有改变我的闹钟音,或者我收到短信时的语气。
以下作品:
private void setRingTone(int RawId, String HumanName, String fileName)
{
Uri path = Uri.parse("android.resource://"+ getPackageName() +"/raw/" + fileName);
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(), RingtoneManager.TYPE_RINGTONE,
path);
Log .i("TESTT", "Ringtone Set to Resource: "+ path.toString());
RingtoneManager.getRingtone(getApplicationContext(), path)
.play();
}
然而,这2个没有:
private void setTextTone(int RawId,String HumanName,String fileName) {
Uri path = Uri.parse("android.resource://"+ getPackageName() +"/raw/" + fileName);
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(), RingtoneManager.TYPE_NOTIFICATION,
path);
Log .i("TESTT", "Ringtone Set to Resource: "+ path.toString());
RingtoneManager.getRingtone(getApplicationContext(), path)
.play();
}
有谁知道为什么通知不会改变短信的声音,但铃声有效。它基本上是相同的代码??
EDIT I found something on Stack Overflow here (But I do Not understand it can someone clarify?) http://stackoverflow.com/questions/9545906/how-do-i-change-the-android-sms-tone-despite-of-current-sms-tone-setting
提前致谢!
答案 0 :(得分:2)
所以解决方法是将原始文件夹中的声音复制到SD卡中,然后执行以下操作:
File k = new File(path, filename);
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "TwiAppclip");
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
values.put(MediaStore.Audio.Media.ARTIST, "cssounds ");
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(k
.getAbsolutePath());
//do a delete here before inserting
Uri newUri = getApplicationContext().getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
RingtoneManager.TYPE_RINGTONE, newUri);