2017-01-06 4 views
0

私は現在、連絡先アプリで作業しており、連絡先をプログラマティックにアンドロイドで共有するためにしばらく検索しています。どのフォーマットで他のデバイスに連絡先を送信するべきかわからなかった。私がテキストとして送信している場合、受信者デバイスのcontactscontract Dbにどのように処理されますか?それを動作させる方法を教えてもらえますか?アンドロイドで連絡先をプログラムで共有する方法

答えて

1

whatsappsのようなものに共有する方法を尋ねるなら、それを送信してみてください。

あなたはこのようにプレーンテキストを送信することができます

Intent whatsappIntent = new Intent(Intent.ACTION_SEND); 
whatsappIntent.setType("text/plain"); 
whatsappIntent.setPackage("com.whatsapp"); 
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "The text you wanted to share"); 
try { 
    activity.startActivity(whatsappIntent); 
} catch (android.content.ActivityNotFoundException ex) { 
    ToastHelper.MakeShortText("Whatsapp have not been installed."); 
} 

は、より多くの詳細については、Share image and text through Whatsapp or Facebookを参照してください。

あなたは私はあなたがWhatsApp

用などの三分のパーティの開発ドキュメントを見てみましょう示唆、というさらにその後、移動したい場合はまた、より一般的な情報は、this page of Android

で見つけることができますHereは、インテントで送信できるものの概要です。 、その後、ACTION_SEND意図を使用して、それを送信します。

+0

おかげ@Raymond・デ・ラ・クロワから連絡先の名前とLookupKeyを入手!私はこれを試してみよう! – Kanagalingam

+0

Goodluck :)私はちょうど参考になるはずのすべての送信タイプを表示するアンドロイドから別の参照サイトを追加しました –

1

あなたは(Contacts.CONTENT_VCARD_URIContactsContract APIを使用して)連絡先のVCardハンドルを取得する必要があります。

String lookupKey = <the contact's lookup key>; 
Uri vcardUri = Uri.withAppendedPath(Contacts.CONTENT_VCARD_URI, lookupKey); 
Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setType(ContactsContract.Contacts.CONTENT_VCARD_TYPE); 
intent.putExtra(Intent.EXTRA_STREAM, shareUri); 
intent.putExtra(Intent.EXTRA_SUBJECT, "Bob Dylan"); // put the name of the contact here 
startActivity(intent); 

は、ここでそれについての詳細を参照してください:@Abhay Maniyarによって削除された質問に答える https://developer.android.com/reference/android/provider/ContactsContract.Contacts.html#CONTENT_VCARD_URI

UPDATE

- contactIdからlookupKeyを取得するには:

Cursor cur = getContentResolver().query(Contacts.CONTENT_URI, new String[] { Contacts.LOOKUP_KEY }, Contacts._ID + " = " + contactId, null, null); 
if (cur.moveToFirst()) { 
    String lookupKey = cur.getString(0); 
} 
0

次のコードを使用してあなたのntact、接触カーソル

private void shareContact() { 
    //lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); 
    String lookupKey2 = lookupKey; 
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey2); 
    Intent intent = new Intent(Intent.ACTION_SEND); 
    intent.setType(ContactsContract.Contacts.CONTENT_VCARD_TYPE); 
    intent.putExtra(Intent.EXTRA_STREAM, uri); 
    intent.putExtra(Intent.EXTRA_SUBJECT, contactName); // put the name of the contact here 
    startActivity(intent); 
} 
関連する問題