views:

293

answers:

1

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"

A: 

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.

CommonsWare
where can I put the file so android can read it?
On the device or emulator, such as on the SD card.
CommonsWare
I managed to put the file in the sdcard but I can't find the path to it? Do you know what is the path to the sdcard?I also got the log using ddms and logcat:It takes too much chars so I put it in the main question.pls take a look on it.
The error message tells you what your problem is: you need the `android.permission.WRITE_CONTACTS` permission. The SD card is located at a path provided by `Environment.getExternalStorageDirectory()`.
CommonsWare
thanks It works now :) but the ringtone isn't playing in a loop, why is that and how can I make it to play in a loop?