无法使用代码更新 Android 中的联系方式
我正在尝试使用此代码更新/更改联系人铃声:
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"
I'm trying to update/change contact ringtone using this code:
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);
I get the message: " the application has stopped unexpectedly"
what is wrong with my code and how do I do it?
thanks
I managed to use logcat and ddms here is the log:
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
the path I used: Environment.getExternalStorageDirectory().getPath() + "/Alex.wav"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您应该使用
adb logcat
、DDMS 或 Eclipse 中的 DDMS 透视图来检查与“应用程序意外停止”相关的 Java 堆栈跟踪,以便您可以看到出了什么问题。在这种情况下,您的 Android 手机和 Android 模拟器都不会具有
D:
驱动器,因为 Android 不是 Windows。First, you should use
adb logcat
, DDMS, or the DDMS perspective in Eclipse to examine the Java stack trace associated with "the application has stopped unexpectedly", so you can see what went wrong.In this case, neither your Android phone nor your Android emulator will have a
D:
drive, since Android is not Windows.