2017-01-06 2 views
0

Ich arbeite derzeit an einer Kontakt-App und ich habe eine Weile gesucht, um einen Kontakt programmatisch in Android zu teilen. Ich wusste nicht, in welchem ​​Format ich den Kontakt an ein anderes Gerät senden sollte. Wenn ich als Text sende, wie es zu Kontakten verarbeitet wird, Vertrag Db in Empfängern Gerät? Können Sie mir bitte vorschlagen, wie es funktioniert?So teilen Sie einen Kontakt programmatisch in Android

Antwort

1

Wenn Sie fragen, wie Sie es zu etwas wie WhatsApps teilen können Sie versuchen, es und eine Absicht zu senden.

können Sie Klartext wie folgt senden:

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."); 
} 

Siehe Share image and text through Whatsapp or Facebook für weitere Details.

Wenn Sie weiter gehen wollen dann, dass ich schlage vor, Sie nehmen einen Blick auf die Drittel Parteientwicklung docs wie für WhatsApp

auch allgemeinere Informationen finden Sie auf this page of Android

finden Here ist eine Übersicht darüber, was Sie in einer Absicht senden können.

+0

Dank @Raymond de la Croix! Ich werde das ausprobieren! – Kanagalingam

+0

Goodluck :) Ich habe gerade eine andere Referenzseite von Android hinzugefügt, die alle Sendearten anzeigt, was auch hilfreich sein sollte –

1

Sie müssen den VCard Griff für den Kontakt kommen (mit ContactsContract API: Contacts.CONTENT_VCARD_URI), und dann die ACTION_SEND Absicht mit senden.

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); 

Weitere Informationen hier: https://developer.android.com/reference/android/provider/ContactsContract.Contacts.html#CONTENT_VCARD_URI

UPDATE

eine gelöschte Frage nach @Abhay Maniyar zu beantworten - die lookupKey von einem ContactID zu bekommen:

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

Verwenden Sie den folgenden Code, um Ihre Kollegen zu teilen NTACT, erhalten Kontakt Name und LookupKey von Kontakt Cursor

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); 
} 
Verwandte Themen