私のアプリはAndroidの連絡先の中に特殊なSYNC4キーを使用して連絡先を作成します。ただし、HTC 10デバイスの連絡先を読むことができません。 HTCデバイスと他のAndroidデバイスとの連絡先の処理に関するいくつかの違いについては読んだことがありますが、残念ながらこの問題の解決策や説明は見つかりませんでした。HTC 10でcontentResolverを使用してAndroidの連絡先を取得すると結果が返されません。
接触の作成は次のように動作:
private static final String SPECIAL_CONTACT_KEY = "_MY_SPECIAL_CONTACT_KEY_";
// Create an operation with the special SYN4 key
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
builder.withValue(RawContacts.ACCOUNT_TYPE, null);
builder.withValue(RawContacts.ACCOUNT_NAME, null);
builder.withValue(RawContacts.SYNC4, SPECIAL_CONTACT_KEY);
ops.add(builder.build());
// Add a 'given name' to the list of operations
builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
builder.withValueBackReference(Data.RAW_CONTACT_ID, 0);
builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
builder.withValue(StructuredName.GIVEN_NAME, "givenName");
ops.add(builder.build());
// Add a 'phone number with type work' to the list of operations
builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
builder.withValueBackReference(Data.RAW_CONTACT_ID, 0);
builder.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
builder.withValue(Phone.TYPE, Phone.TYPE_WORK);
builder.withValue(Phone.NUMBER, "phoneNumber");
ops.add(builder.build());
// Add a 'note' to the list of operations (to be able to visually discern the contact from other contacts)
builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
builder.withValueBackReference(Data.RAW_CONTACT_ID, 0);
builder.withValue(Data.MIMETYPE, Note.CONTENT_ITEM_TYPE);
builder.withValue(Note.NOTE, "note");
ops.add(builder.build());
ContentProviderResult[] result = App.getContext().getContentResolver().applyBatch(AUTHORITY, ops);
接点(S)は次のように取り出すことができる。
// Retrieve our own contacts using the special SYNC4 key
Uri uri = Phone.CONTENT_URI;
String[] projection = {Phone.NUMBER};
String mySpecialSelection = RawContacts.SYNC4 + "='" + SPECIAL_CONTACT_KEY + "'";
Cursor cursor = App.getContext().getContentResolver().query(uri, projection, mySpecialSelection, null, null);
カーソルは、すべてのデバイス上の正しい連絡先データで満たされていますHTCではカーソルは空です。
なぜあなたは 'SYNC4'を使用していますか? – pskink
正直言って、それはすでに同僚によって使用されていた、私はそれが他の人との接触を識別する特定のマーカーだと言われました。私はそれが何であるかはわかりませんが、よりよいマーカーのアドバイスがあれば、;-) あなたはそれがHTCの問題に関連していると思いますか? –