我試圖將手機中的所有聯繫人與我的應用程序鏈接起來。然後從聯繫應用程序啓動我的應用程序。在api < 23它工作正常。但在api> 23的聯繫人得到重複。所以讓我知道任何人試過這!! !!這是我試過..!從Android API中的本地聯繫人應用程序啓動我的應用程序23
public class ContactsSync extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
String name, number, id;
for (int i = 0; i <=mIDs.size(); i++) {
//name = mNames.get(i);
id = mIDs.get(i);
number = mNumbers.get(i);
ContactsManager.addContact(Paymoney.this, new MyContact(id, number));
}
return null;
}
@Override
protected void onPostExecute(String s) {
getContactDataAfter();
}
}
公共靜態無效的addContact(上下文的背景下,MyContact接觸){
ContentResolver resolver = context.getContentResolver();
boolean mHasAccount = isAlreadyRegistered(resolver, contact.Id);
if(mHasAccount){
} else {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
// insert account name and account type
ops.add(ContentProviderOperation
.newInsert(addCallerIsSyncAdapterParameter(ContactsContract.RawContacts.CONTENT_URI, true))
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, Constants.ACCOUNT_NAME)
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, Constants.ACCOUNT_TYPE)
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE,
ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
.build());
ops.add(ContentProviderOperation
.newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Data.CONTENT_URI, true))
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
.withValue(CommonDataKinds.Phone.NUMBER, contact.number)
.build());
ops.add(ContentProviderOperation
.newInsert(addCallerIsSyncAdapterParameter(ContactsContract.Data.CONTENT_URI, true))
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, MIMETYPE)
.withValue(ContactsContract.Data.DATA1, 12345)
.withValue(ContactsContract.Data.DATA2, "user")
.withValue(ContactsContract.Data.DATA3, "Send Money")
.build());
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
顯示'ContactsManager.addContact'的代碼 – marmor
@marmor請看看 – gStephin