我正在尝试使用以下代码更新/更改联系人铃声:
ContentValues values = new ContentValues();
values.put(ContactsContract.Data.CUSTOM_RINGTONE, "D:/TempDownloads/BurpSounds/Alex.wav");
getContentResolver().update(ContactsContract.Contacts.CONTENT_URI, values , "DISPLAY_NAME = 'Ani'", null);
我收到消息:“应用程序已意外停止”
我的代码有什么问题,我该怎么做?
谢谢
我设法使用 logcat 和 ddms 这里是日志:
04-10 13:47:45.419: ERROR/AndroidRuntime(399): Caused by: java.lang.SecurityException: Permission Denial: writing com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/contacts from pid=399, uid=10025 requires android.permission.WRITE_CONTACTS
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at android.os.Parcel.readException(Parcel.java:1218)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at android.content.ContentProviderProxy.update(ContentProviderNative.java:532)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at android.content.ContentResolver.update(ContentResolver.java:737)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at com.example.helloandroid.HelloAndroid.getContactList(HelloAndroid.java:36)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at com.example.helloandroid.HelloAndroid.onCreate(HelloAndroid.java:19)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-10 13:47:45.419: ERROR/AndroidRuntime(399): ... 11 more
我使用的路径:Environment.getExternalStorageDirectory().getPath() + "/Alex.wav"