@Override
    protected RawContactDeltaList doInBackground(Intent... params) {

      final Intent intent = params[0];

      final ContentResolver resolver = activityTarget.getContentResolver();

      // Handle both legacy and new authorities
      final Uri data = intent.getData();
      final String authority = data.getAuthority();
      final String mimeType = intent.resolveType(resolver);

      mSelection = "0";
      String selectionArg = null;
      if (ContactsContract.AUTHORITY.equals(authority)) {
        if (Contacts.CONTENT_ITEM_TYPE.equals(mimeType)) {
          // Handle selected aggregate
          final long contactId = ContentUris.parseId(data);
          selectionArg = String.valueOf(contactId);
          mSelection = RawContacts.CONTACT_ID + "=?";
        } else if (RawContacts.CONTENT_ITEM_TYPE.equals(mimeType)) {
          final long rawContactId = ContentUris.parseId(data);
          final long contactId = queryForContactId(resolver, rawContactId);
          selectionArg = String.valueOf(contactId);
          mSelection = RawContacts.CONTACT_ID + "=?";
        }
      } else if (android.provider.Contacts.AUTHORITY.equals(authority)) {
        final long rawContactId = ContentUris.parseId(data);
        selectionArg = String.valueOf(rawContactId);
        mSelection = Data.RAW_CONTACT_ID + "=?";
      }

      // Note that this query does not need to concern itself with whether the contact is
      // the user's profile, since the profile does not show up in the picker.
      return RawContactDeltaList.fromQuery(
          RawContactsEntity.CONTENT_URI,
          activityTarget.getContentResolver(),
          mSelection,
          new String[] {selectionArg},
          null);
    }
Esempio n. 2
0
  private String getAccounts() {
    String result = "<table>";
    List<SyncAdapterType> unknownAdapters = new ArrayList<SyncAdapterType>();

    result +=
        "<tr><th>Name</th><th>Type</th><th>Authority</th><th>Writable</th><th>Default</th></tr>\n";

    Account defaultContactsAccount = ToolsAccounts.identifyDefaultContactAccount(_context);

    // all online accounts defined by system & user.
    Account[] deviceAccounts = AccountManager.get(_context).getAccounts();

    List<Account> listAccounts = new ArrayList<Account>();
    for (Account account : deviceAccounts) {
      if (defaultContactsAccount == null || !account.equals(defaultContactsAccount)) {
        listAccounts.add(account);
      }
    }

    if (defaultContactsAccount != null) {
      listAccounts.add(0, defaultContactsAccount);
    }

    for (SyncAdapterType syncAdapterType : ContentResolver.getSyncAdapterTypes()) {
      unknownAdapters.add(syncAdapterType);
    }

    boolean bEven = true;
    // walk through all user online accounts, and keep contacts sync accounts
    for (Account account : listAccounts) {
      boolean bFound = false;

      // search SyncAdapter details
      for (SyncAdapterType syncAdapterType : ContentResolver.getSyncAdapterTypes()) {
        String defaultAuth = "";

        if (syncAdapterType.accountType.equals(account.type)) {
          unknownAdapters.remove(syncAdapterType);

          bFound = true;
          // match: this account has contact authority.
          boolean bWritable = syncAdapterType.supportsUploading();

          String rowClass = "account" + (bEven ? "Even" : "Odd");
          if (account.equals(defaultContactsAccount)
              && ContactsContract.AUTHORITY.equals(syncAdapterType.authority)) {
            rowClass = "accountDefault";
            defaultAuth = "contacts (syncadapter)";
          }
          result += "<tr class='" + rowClass + "'>";
          result +=
              "<td>"
                  + account.name
                  + "</td><td>"
                  + account.type
                  + "</td><td>"
                  + syncAdapterType.authority
                  + "</td><td>"
                  + bWritable
                  + "</td><td>"
                  + defaultAuth
                  + "</td></tr>\n";
        }
      }

      if (!bFound) {
        if (account.equals(defaultContactsAccount)) {
          result += "<tr class='accountDefault'>";
          result +=
              "<td>"
                  + account.name
                  + "</td><td>"
                  + account.type
                  + "</td><td>"
                  + ContactsContract.AUTHORITY
                  + "</td><td>true</td><td>contacts (no syncadapter)</td></tr>\n";
        } else {
          String rowClass = "account" + (bEven ? "Even" : "Odd");
          result += "<tr class='" + rowClass + "'>";
          result +=
              "<td>"
                  + account.name
                  + "</td><td>"
                  + account.type
                  + "</td><td>unknown</td><td>unknown</td><td></td></tr>\n";
        }
      }

      bEven = !bEven;
    }

    for (SyncAdapterType syncAdapterType : unknownAdapters) {
      String rowClass = "account" + (bEven ? "Even" : "Odd");
      result += "<tr class='" + rowClass + "'>";
      result +=
          "<td>(unknown)</td><td>"
              + syncAdapterType.accountType
              + "</td><td>"
              + syncAdapterType.authority
              + "</td><td>"
              + syncAdapterType.supportsUploading()
              + "</td><td></td></tr>\n";
    }

    result += "</table>";

    return result;
  }