Setting contact custom ringtone, how?

后端 未结 2 1756
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 12:40

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: ContactsContra

2条回答
  •  我在风中等你
    2020-12-03 13:29

    I found out how it works. Below you can see the fixed code code:

        Uri contactData = ContactsContract.Contacts.CONTENT_URI;
        String contactId = contactData.getLastPathSegment();
    
        Cursor localCursor = managedQuery(contactData, PROJECTION, null, null, null);
        localCursor.move(120/*CONTACT ID NUMBER*/);
    
        String str1 = localCursor.getString(localCursor.getColumnIndexOrThrow("_id"));
        String str2 = localCursor.getString(localCursor.getColumnIndexOrThrow("display_name"));
        Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, str1);
        ContentValues localContentValues = new ContentValues();
    
        localContentValues.put(ContactsContract.Data.RAW_CONTACT_ID, contactId);
        localContentValues.put(ContactsContract.Data.CUSTOM_RINGTONE, f.getAbsolutePath()+"/Adventure.ogg");
        getContentResolver().update(localUri, localContentValues, null, null);
        Toast.makeText(this, "Ringtone assigned to: " + str2, 0).show();
    

    Just change the contact id number to the id of the contact you want to change.

提交回复
热议问题