I'm getting Cursor with RAW_CONTACTS for person in my app.
How can i use this data to start an Intent to communicate with this person via one of selected raw-contacts?
For example, one contacts has several raw-contacts: phone, whatsapp, viber etc. When i click whatsapp raw_contact, app should start WhatsApp to communicate with selected person.
So simple...
Uri uri = Uri.parse("content://com.android.contacts/data/" + rawContactId);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(uri, rawContactMimetype);
Related
I am using this code to call WhatsApp directly from my Call Logs app. This works well, but only if the phone number includes a valid country code. For example calling WhatsApp with 919789006685 works but calling it with 97890 06685 does not work. Here 91 is the country code.
Since my app reads phone numbers from Call Logs, I should be able to invoke WhatsApp with any valid contact phone number, irrespective of the stored phone number format. It is possible that users store numbers in their contacts which do not include country codes. So is there a workaround for this issue?
Code used within my app:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
String waNumber = contactPhone.replace("+", "");
sendIntent.putExtra("jid", waNumber + "#s.whatsapp.net");
startActivity(sendIntent);
Here is the complete solution. May be useful for people who are trying the same from their apps. Thanks to Sourav Ganguly for the link.
android-make whatsapp call
Retreive the ID for the selected Contact.
Get all the RAW Contact Id's for the contact id from ContactsContract.RawContacts
Query the ContactsContract.Data table for all Raw Contacts and retrieve the column ContactsContract.Data._ID
Since a contact may have several phone numbers active on WhatsApp, you may want to check additionally the column ContactsContract.Data.DATA3 to filter out the phone number you want to match
To start a WhatsApp conversation use vnd.android.cursor.item/vnd.com.whatsapp.profile and vnd.android.cursor.item/vnd.com.whatsapp.voip.call if you want to start a WhatsApp call
Use the ID from step 3 to start WhatsApp. Here is sample code:
String data = "content://com.android.contacts/data/" + dataId;
String type = "vnd.android.cursor.item/vnd.com.whatsapp.profile";
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.setDataAndType(Uri.parse(data), type);
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
WhatsApp for an specific phone number
val whatsAppIntent = Intent(Intent.ACTION_VIEW)
val encodedText = URLEncoder.encode("Helo World", "UTF-8")
whatsAppIntent.data = Uri.parse("http://api.whatsapp.com/send?phone=$phoneNumber&text=$encodedText")
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/html");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<p>https://play.google.com/store/apps/details?id=" + context.getPackageName() + "</p>"));
context.startActivity(Intent.createChooser(sharingIntent, "Share using"));
I have a raw contact ID for a contact in my application. I want to open the native contact phonebook for editing in my contact (basically the contact in edit mode in native address book). How can I do that?
What I understand from your question is that, you have a contact id you want to open that in android native address book against that id. If that is the case then below code should help you
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf("18"));
intent.setData(uri);
startActivity(intent);
In String.valueOf() method provide the contact id you want to open.
Problem resolved.
I did this with below code
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setData(ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactID));
startActivity(intent);
I'm trying to find out whether a particular contact is a whatsapp user or not.
This goes my requirement:
I have a text to share and also have a phone number of a person as well. The priority of my sharing goes as follows
If the phone number is already present in CONTACTS and :
if the contact is a whatsapp user, I should call sharing intent of SEND with package set as "com.whatsapp"
i.e:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
if the contact not a whatsapp user, I should call intent for default messaging app.
i.e :
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", message );
startActivity(intent);
If the phone number is not present, create a contact and do as above.
My question now is, how do I find out whether my contact is a whatsapp user or not? Is whatsapp providing any API to find out that?
Thanks in advance
PS: I do not want to show a general sharing intent which shows a list of sharing apps. I may do that only if the device does not have whatsapp application at all.
I am trying to send open fb-messenger in a specific chat with a user from within my app. I have the user's app_scope_id, relevant for my app. However, from what I could figure out so far, I need the global facebook id in order for the messenger to launch in a conversation with that person. Is there any way to achieve that with the app_scope_id?
Code:
Uri uri = Uri.parse("fb-messenger://user/");
uri = ContentUris.withAppendedId(uri,[APP SCOPE ID]);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Intent pickContactIntent = new Intent(Intent.ACTION_PICK,Uri.parse("content://contacts"));
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
I saw the intent above is only allowed to pick the contacts but I need to pick call logs, favorite, contact just like Android OS Contact Book , How should i achieve this ?
Is there any Intent which allows this or do we need to code it ?