0

Ich überweise den Kontonamen aus einer Liste an diese Methode. Jetzt möchte ich wissen, welche dieser Kontonamen nur in der Kontakttabelle gelesen werden, so dass ich den Cursor nur einmal wiederhole, um die Kontakt-ID vom Roh-Cursor zu erhalten. Nachdem ich die contact_id bekommen habe, benutze ich den Telefoncursor, um zu überprüfen, ob die angegebene ID schreibgeschützt ist oder nicht, aber ich kann das nicht tun. Bitte schauen Sie unterSo erhalten Sie nur die Kontonamen aus der Kontakt-ID in Kontakte in Android

private void displayAllContactsByType(String accountName) { 

    Cursor rawCursor,phones = null; 

    rawCursor = cResolver.query(
      ContactsContract.RawContacts.CONTENT_URI, 
      new String[]{ContactsContract.RawContacts.CONTACT_ID}, 
      ContactsContract.RawContacts.ACCOUNT_NAME + "= ?", 
      new String[]{accountName}, 
      null); 


    int contactIdColumn = rawCursor.getColumnIndex(ContactsContract.RawContacts.CONTACT_ID); 
    int rawCursorCount = rawCursor.getCount(); 


    Utils.Log("Account Name", accountName); 

    Utils.Log("Raw Size", " " + rawCursorCount); 
    rawCursor.moveToFirst(); 
    Long contactId = rawCursor.getLong(contactIdColumn); 


    phones = cResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
      null, 
      ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ? AND "+ContactsContract.RawContacts.ACCOUNT_NAME + "= ?", 
      new String[]{String.valueOf(contactId),accountName}, 
      null); 

    phones.moveToFirst(); 




    String isReadOnly= phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.IS_READ_ONLY)); 
    Utils.Log("Raw Size", isReadOnly); 


} 

Antwort

3

Sie müssen ein Konto Kontakte gehen nicht über das zu überprüfen, können Sie einfach über die SyncAdapters auf dem Gerät durchlaufen und ihre Eigenschaften überprüfen:

final SyncAdapterType[] syncs = ContentResolver.getSyncAdapterTypes(); 
for (SyncAdapterType sync : syncs) { 
    Log.d(TAG, "found SyncAdapter: " + sync.accountType); 
    if (ContactsContract.AUTHORITY.equals(sync.authority)) { 
     Log.d(TAG, "SyncAdapter supports contacts: " + sync.accountType); 
     boolean readOnly = !sync.supportsUploading(); 
     Log.d(TAG, "SyncAdapter read-only mode: " + readOnly); 
     if (readOnly) { 
      // we'll now get a list of all accounts under that accountType: 
      Account[] accounts = AccountManager.get(this).getAccountsByType(sync.accountType); 
      for (Account account : accounts) { 
       Log.d(TAG, account.type + "/" + account.name); 
      } 
     } 
    } 
} 

Hoffe das hilft.

+0

Vielen Dank. –

+0

Ich möchte auch nur das Konto mit Sync-Adapter nur mit Telefonkontakten bekommen. –

+0

Was meinen Sie mit 'Nur Telefonkontakte '? Sie meinen, das spezielle Kontakte-Konto namens "Nur Telefon (unsynchronisiert)", wenn Sie dies tun, hat es kein SyncAdapter, weil es ein unsynchronisiertes Konto ist. – marmor

Verwandte Themen