16

連絡先のIDでAndroidの連絡先カードを開くことは可能ですか? 電話番号で動作します。これが例です、私が使用する場合

Intent i = new Intent();
i.setAction(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
i.setData(Uri.fromParts("tel", "123456", null)); //<---- Change here from Phone to IDcontext.startActivity(i);

しかし、連絡先の電話番号が変更される場合など、ID でこの連絡先カードを開きたいと考えています。

4

3 に答える 3

44

ACTION_VIEW を使用し、連絡先 ID を使用して連絡先 URI を作成するか、連絡先検索 URI が既にある場合はそれを使用します (推奨)。

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
    intent.setData(uri);
context.startActivity(intent);
于 2010-11-25T09:43:34.583 に答える
6

次の URI を使用します。

Uri.Builder newUriBuilder = ContactsContract.Contacts.CONTENT_LOOKUP_URI.buildUpon();
newUriBuilder.appendPath("/").appendPath(theContactKey)
i.setData(newUriBuilder.build());

CONTENT_LOOKUP_URI の API ドキュメントを参照すると、この URI がどのように機能するかについての詳細を確認できます。

于 2010-11-25T09:43:06.410 に答える
4

ここにリストされている方法を使用して連絡先カードを開こうとしていましたが、どういうわけか連絡先アクティビティが開いた直後に閉じていました。

コンタクト アクティビティが私の古いコンテンツ URI を受け入れていないようです。

適切なコンテンツURIを取得するためgetLookupUri (long contactId, String lookupKey)のクラスのメソッドを使用してこの問題を解決しましたhttps://developer.android.com/reference/android/provider/ContactsContract.Contacts.html#getLookupUri(long, java.lang.String)ContactsContract.Contacts

したがって、連絡先カードを開くためのコードは次のようになります。

Intent intent = new Intent(Intent.ACTION_VIEW);
String lookupKey = phonesCursor.getString(phonesCursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup.LOOKUP_KEY));
long contactId = phonesCursor.getLong(phonesCursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID));
Uri uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
intent.setData(uri);
startActivity(intent);
于 2015-07-16T05:33:39.847 に答える