Can I open chat with an unknown contact? - android

I have an unknown number I need to start chat with it.
Intent intent = new Intent();
intent
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, "test")
.putExtra("jid", "999999999#s.whatsapp.net")
.setType("text/plain")
.setPackage("com.whatsapp");
activity.startActivity(intent);
Whatsapp openы a window where I have to select a contact.
Is it possible to open Whatsapp and start a chat with it?

I found an answer here
String phone = "79999999999";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("whatsapp://send?phone=" + phone));
startActivity(intent);
Phone should be without any characters only digits. This number is valid 79999999999, this number is not valid +79999999999

Related

Opening a WhatsApp chat with a specific contact by clicking on a button in my app (Kotlin)

How can I Open a Whatsapp chat with a specific contact by clicking on a button in my app?
That's the code I use. It opens WhatsApp and let me search the contact I want to send the message to, but it doesn't open the WhatsApp chat with the specific contact number I gave it to.
whatsappButton.setOnClickListener{
var con = itemView.context
val textToShare = "*כח אדם*"
val phoneNumber = blogPost.phone
val sendIntent = Intent()
sendIntent.action = Intent.ACTION_SEND
sendIntent.type = "text/plain"
sendIntent.putExtra("jid", phoneNumber+"#s.whatsapp.net")
sendIntent.putExtra(Intent.EXTRA_TEXT, textToShare)
val extra = sendIntent.extras
startActivity(con,sendIntent,extra)
}
If you want send a message to a specific contact from Contacts app, you should first require permission to access contacts, get the number and try with this:
Intent sendIntent = new Intent("android.intent.action.MAIN");
sendIntent.setComponent(new ComponentName("com.whatsapp","com.whatsapp.Conversation"));
sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("YOUR_PHONE_NUMBER")+"#s.whatsapp.net");
startActivity(sendIntent);
Ref: https://stackoverflow.com/a/40285262/2895571
Please check this answer here
Use the following bit of code:
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
i.setType("text/plain");
i.setPackage("com.whatsapp"); // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);
First option: using Uri to convert whatsapp web url into button:
open_whatsapp.setOnClickListener {
val url = "https://api.whatsapp.com/send?phone=XXXXXXXXXX"
val openWhatsappIntent = Intent(Intent.ACTION_VIEW)
openWhatsappInten.data = Uri.parse(url)
startActivity(openWhatsappInten)
}
Second option; this is used as a href in web development :
Tel: XXX XXXX XX
maybe you can add Html format into TextView (Html.fromHtml()) and enable links clickeable to open the whatsapp application.
if you want send message to particular contact in whatsapp , use below url and particular mobile no to the Intent(including Country code).
String url = "https://wa.me/";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url+mobile_no));
startActivity(browserIntent);

Choose among SMS, WhatsApp, or Telegram to send message

At a contact list in my Android app, there is an option to launch WhatsApp implemented as follows:
// Country code is required
final String phoneNumber = "+15555555555";
final String packageName = "com.whatsapp";
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
if (null == intent) {
// Launch Google Play at WhatsApp homepage
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + MESSAGE_PACKAGE_NAME));
startActivity(intent);
return;
}
intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phoneNumber));
intent.setPackage(packageName);
startActivity(intent);
but this only allow me to send messages through WhatsApp.
Removing the package name and setting the intent type to
intent.setType("vnd.android-dir/mms-sms");
launched the SMS application.
How can we choose among all apps installed at an Android device that use the phone number as and identifier (Hangouts, SMS, Skype, Line, Telegram, Viber, WhatsApp, etc)?
Fortunately Android Intent.createChooser is smart enough to figure out the apps that understand the phone numbers as an identifier :-)
// Country code is required
String phoneNumber = "+15555555555";
Uri uri = Uri.parse("smsto:" + phoneNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(Intent.createChooser(intent, "Send message"));

Android Intent for deep-linking to Deezer Search

I am trying to perform a search on Deezer by sending the following intent:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.deezer.com/search/" + query));
this.startActivity(intent);
In a previous version the web browser opened with a link saying "Open in Deezer" (or the like).
But in the current version this doesn't work anymore.
Is there any way to open the Deezer app and perform a search?
I have already tried the following (without success):
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://search/" + query));
this.startActivity(intent);
There are many deeplinks you can use to search for content inside the Deezer app. You do have the basic search like this :
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://www.deezer.com/search/" + query));
this.startActivity(intent);
But you can also be more precise :
// Search for an artist, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/artist?query" + query));
this.startActivity(intent);
// Search for an album, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/album?query" + query));
this.startActivity(intent);
// Search for a track, will display the best match
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer-query://www.deezer.com/track?query" + query));
this.startActivity(intent);
I believe it should be
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("deezer://www.deezer.com/search/" + query));
this.startActivity(intent);
The scheme of the Uri needs to be deezer. You have set it as http.
Try this. This should work.

display contact with given display name android

SO,how do i do it? I have tried the following
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
context.startActivity(intent);
The above works only with mailto or tel, what about name?
you can also send Person Name using Intents.Insert.NAME with Intent as:
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
// add name here
intent.putExtra(Intents.Insert.NAME, sender_Name_here);
context.startActivity(intent);

Pick a contact from the Contacts app; but only list contacts with email

I'm trying to select contacts depending on their information, it's working for phone numbers (as far as I can see); but when I try to pick contacts with only email it fails with the following error:
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT typ=vnd.android.cursor.item/email_v2 }
Here's my code (or rather the important part):
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
if( SMS )
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
if( EMAIL )
intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
startActivityForResult(intent, PICK_CONTACT);
I think you should be using Intent intent = new Intent(Intent.ACTION_PICK, uri), where uri is one of CommonDataKinds.Email.CONTENT_URI or CommonDataKinds.Phone.CONTENT_URI. That way, it'll display only contacts with an email or phone.

Categories

Resources