联系人铃声已设置,但当该联系人呼叫时,android.process.phone被终止
我正在尝试将存储在我的联系人铃声已设置,但当该联系人呼叫时,android.process.phone被终止,android,Android,我正在尝试将存储在我的/storage/sdcard0/Ringtones上的铃声(mp3文件)设置为我想要的联系人。在运行应用程序时,铃声会被保存,当我打开联系人时,我可以看到铃声列表。但是,当那个联系人打电话时 我没有接到电话,下面的消息出现在我的屏幕上:process com.android.phone stops. 下面是我用来为联系人设置铃声的代码- Nb: K is the File object which has the filename and path for the
/storage/sdcard0/Ringtones
上的铃声(mp3文件)设置为我想要的联系人。在运行应用程序时,铃声会被保存,当我打开联系人时,我可以看到铃声列表。但是,当那个联系人打电话时
我没有接到电话,下面的消息出现在我的屏幕上:process com.android.phone stops.
下面是我用来为联系人设置铃声的代码-
Nb: K is the File object which has the filename and path for the .mp3 clip
String str1 = c.getString(c.getColumnIndexOrThrow("_id"));
Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, str1);
ContentValues localContentValues = new ContentValues();
localContentValues.put(ContactsContract.Data.RAW_CONTACT_ID, contactId);
localContentValues.put(ContactsContract.Contacts.CUSTOM_RINGTONE, k.getAbsolutePath());
getContentResolver().update(localUri, localContentValues, null, null);
联系人呼叫时出现Logcat错误:
01-16 15:27:09.632: E/AndroidRuntime(24282): FATAL EXCEPTION: main
01-16 15:27:09.632: E/AndroidRuntime(24282): java.lang.NullPointerException
01-16 15:27:09.632: E/AndroidRuntime(24282): at com.android.phone.Ringer.isValidRingtoneURI(Ringer.java:742)
01-16 15:27:09.632: E/AndroidRuntime(24282): at com.android.phone.CallNotifier.onQueryComplete(CallNotifier.java:2079)
您应该提供Uri而不是绝对路径(请参阅): ContentValues.put(字符串,Uri);不存在。正确的方法应该是uriOfRt.toString()
Uri uriOfRt = Uri.fromFile(new File( k.getAbsolutePath()));
localContentValues.put(ContactsContract.Contacts.CUSTOM_RINGTONE, uriOfRt);