私はAccount Syncをやっており、その過程にはカスタム着信音追加されました。ここで着信音を追加するための私の方法は次のとおりです。Android:連絡先に着信音を追加しても私が追加した連絡先では動作しませんが、以前の同期で追加した連絡先で働いています
private static void ringtoneSync(ContentResolver resolver, String username, Context context) {
ContentValues values = new ContentValues();
Log.e("SYNC", "setting ringtone for " + username);
long rawContactId = lookupRawContact(resolver, username);
long contactId = getContactId(resolver, rawContactId);
File root = Environment.getExternalStorageDirectory();
TagDBAdapter adapter = new TagDBAdapter(context);
adapter.open();
String ringtone = adapter.getContactRingtonePath(username);
adapter.close();
Log.e("test", "ringtone checkpoint name here: " + ringtone);
File file = new File(root, "tag/ringtones/"+ ringtone + ".mp3");
if(file.exists()) {
Log.e("test", "ringtone checkpoint if file exists");
Uri oldUri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
resolver.delete(oldUri, MediaStore.MediaColumns.DATA + "=\"" + file.getAbsolutePath() + "\"", null);
values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, ringtone);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
Uri uri = MediaStore.Audio.Media.getContentUriForPath(file.getAbsolutePath());
Uri newUri = resolver.insert(uri, values);
String uriString = newUri.toString();
values.put(ContactsContract.Contacts.CUSTOM_RINGTONE, uriString);
Log.e("Uri String for " + username, uriString);
resolver.update(ContactsContract.Contacts.CONTENT_URI, values, Contacts._ID + "=" + contactId, null);
}
}
この方法では、私が事前に初めてアカウントに連絡先を追加していたときを除いて、素晴らしい作品。あなたはそれが新規または既存の連絡先であれば、それは非常に同様に関係なく、呼ばれて見ることができるように
for(Contact contact : friends) {
Log.e("SYNCING CONTACTS", "Start for loop");
username = contact.getUsername();
rawContactId = lookupRawContact(resolver, username);
if(rawContactId != 0) {
if(!contact.isDeleted()) {
Log.e("SYNCING CONTACTS", "Updating " + username);
updateContact(context, resolver, account, contact, rawContactId, batchOperation);
ringtoneSync(resolver, username, context);
}
else {
Log.e("SYNCING CONTACTS", "Deleting " + username);
deleteContact(context, rawContactId, batchOperation);
}
}
else {
if(!contact.isDeleted()) {
Log.e("SYNCING CONTACTS", "Adding " + username);
addContact(context, account, contact, batchOperation);
ringtoneSync(resolver, username, context);
}
}
を、それだけで、実際に既存の連絡先のに動作します:追加の連絡先への私の呼び出しは、このように構成されています。さらに、着信音が正常に追加されなくても、チェックポイントとして入力したログラインはすべてlogcatに正確に表示されます。
ここで何が起こっているのか、私の人生はわかりません。