I know how to change phone ringtone, also how to get contacts, but how can I set a ringtone for a specific contact?
So how do I use the method: ContactsContract.Contacts.CUSTOM_RINGTONE
?
I have tried it like this:
Uri contactUri = ContactsContract.Contacts.CONTENT_URI;
String[] PROJECTION = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts.HAS_PHONE_NUMBER,
};
String SELECTION = ContactsContract.Contacts.HAS_PHONE_NUMBER + "='1'";
Cursor contacts = managedQuery(contactUri, PROJECTION, SELECTION, null, null );
while (contacts.moveToNext())
{
String Name=contacts.getString(contacts.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
}
String str1 = contacts.getString(contacts.getColumnIndexOrThrow("_id"));
Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, str1);
ContentValues localContentValues = new ContentValues();
localContentValues.put(ContactsContract.Contacts.CUSTOM_RINGTONE,
f.getAbsolutePath()+"/Adveture.ogg");
MainActivity.this.getContentResolver().update(localUri, localContentValues, null, null);
But it's not working.
I found out how it works. Below you can see the fixed code code:
Just change the contact id number to the id of the contact you want to change.
To open the default contact search of android use this code:
In the onActivityResult method you can use this code (similar to Rotary Heart's code) to set the contacts ringtone:
Note: you still have to set the f variable (in code f.getAbsolutePath()+"/Adventure.ogg") to your file (ringtone) you like to set.
This code was tested with android 2.3. Maybe there are changes necessary for higher versions.