2014-01-16 49 views
0

我試圖將我的/storage/sdcard0/Ringtones上存儲的鈴聲(mp3文件)設置爲我希望的聯繫人。在運行應用程序時,鈴聲會保存,當我打開該聯繫人時,我可以看到它已列出。但是,當該聯繫人呼叫時。聯繫人鈴聲設置,但android.process.phone在該聯繫人調用時死亡

我沒有得到調用和下面的消息出現在我的屏幕上: 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) 

回答

0

你應該提供開放的,而不是絕對路徑(見here):

Uri uriOfRt = Uri.fromFile(new File(k.getAbsolutePath()));  
localContentValues.put(ContactsContract.Contacts.CUSTOM_RINGTONE, uriOfRt); 
+0

ContentValues.put(String,Uri);不存在。正確的事情是uriOfRt.toString() –

相關問題