0
如果我試圖將位於我的SD卡中的鈴聲指定給特定的聯繫人。它的工作完美,但問題是,該鈴聲分配給所有的聯繫人,而不是特定的聯繫人。以編程方式指定在Android系統中聯繫手機鈴聲
這裏是我的代碼: -
((ListView) v.findViewById(R.id.contact_list)).setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
ContactModel contactModel = (ContactModel) adapterView.getItemAtPosition(i);
AudioModel audioModel = (AudioModel) getArguments().getSerializable("AudioModel");
ContentValues values = new ContentValues();
String username = contactModel.getName();
Log.e("SYNC", "setting ringtone for " + username);
ContentResolver resolver = getActivity().getContentResolver();
File root = Environment.getExternalStorageDirectory();
Log.e("test", "ringtone checkpoint name here: beautiful ");
File file = new File(audioModel.getPath());
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);
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactModel.getContact_id());
values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "Beautiful");
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 " + ContactsContract.Contacts.CONTENT_URI, uriString);
long updated = resolver.update(contactUri, values,null, null);
Toast.makeText(getActivity(), "Updated : " + updated, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getActivity(), "File does not exist", Toast.LENGTH_LONG).show();
}
}
});
如果我使用這個代碼,它的工作,但鈴聲分配給所有聯繫人沒有一個。
resolver.update(ContactsContract.Contacts.CONTENT_URI, values,null, null);
但是,當我使用此代碼,它不工作。
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactModel.getContact_id());
resolver.update(contactUri, values,null, null);
你能告訴我該怎麼把在WHERE子句 – asdf 2015-02-07 10:40:04