How to WhatsApp Call without saving number manually - android

I am trying to write a code to whatsapp call a mobile number, without saving it to the phonebook.
I have written the code as:
Intent callIntent = new Intent("android.intent.action.MAIN");
callIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
callIntent.putExtra("jid", "19876543210#s.whatsapp.net");//phone number without "+" prefix
callIntent.putExtra(Intent.EXTRA_TEXT, "voip-call");
callIntent.putExtra("call", true);
callIntent.setAction(Intent.ACTION_CALL);
callIntent.setPackage("com.whatsapp");
startActivity(callIntent);
But it is not working.
Any sort of help would be beneficial for my learning.

Related

Android Intent to call Whatsapp from code

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

How to pass a comma ',' character to ACTION_DIAL intent in Android

I would like to be able to pass commas ',' into an Action_dial intent. A comma is used for a pause when pressing numbers for an automated phone menu system.
These can be placed in numbers in Contacts and it will work fine but when trying to Parse or Encode a URI to pass this into the Action_Dial intent, it passes the number in right up until the ',' and then will not pass anything after the ','.
I have tried several different ways of doing this several different ways.
Such as...
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:14051234567,,3,1"));
startActivity(intent)
and..
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.fromParts("tel", "14051234567", ","));
startActivity(callIntent);
and
Intent callIntent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + Uri.encode("14051234567")+ Uri.encode(",")));
and every other way that I've found here on StackOverflow.
Is there a way to make this happen?
EDIT-
Maybe this can't be made to work?? I just ran across this Android Bug report that was closed by Google but not ever fixed. Lame Google.
https://code.google.com/p/android/issues/detail?id=7993

How to make a special number phone call in Android ending with #

I'm a new android application programmer.
I created a button in my application that calls a number ie. *144# but it keep ignoring the # and dialing *144 only.
How do i ensure it calls the whole number?
Code Snippet:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:*144#"));
startActivity(callIntent);`
Url encode it.
String number = "tel:*144%23";
callIntent.setData(Uri.parse(asd));
Or if you need a more general approach (like if you numbers change...) - encode the data part of the URI with a URLEncoder.
String number = "tel:"+ URLEncoder.encode("*144#");
....
Simple use Uri encode :
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ Uri.encode("*144#")));
startActivity(callIntent);
You can try this:
Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:*144" + Uri.encode("#")));
startActivity(callIntent);
it worked for me.
# is a special character that sends command to operator. I don't think that you can actually call any number ending with #.

android starting a phone call intent with # in the URI

I tried do the below for a phone call intent and I still keep getting the "#" removed from the number been called. Please see code below... The # at the end get translated into a %23 on printing out the contents of the string to a console. I am testing on a Samsung S4 phone which then generates a USSD code error running. Is there something wrong with the phone or the code below
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse("tel:" + Uri.encode("*222*"+ rechargeNumber + "#");));
startActivity(phoneCallIntent);
don't use Uri.encode().
Use the following code. I think it will help you.
String uri = "tel:" +"*222*"+ rechargeNumber + "#" ;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
Intent you're looking for is android.intent.action.CALL_PRIVILEGED.
This might be helpful to you
using android dialer in 3rd party app

Call forwarding

I would like to forward all calls to my number on to the new predefined number
automatically. Is it possible to forward incoming call ?
Probably it is possible for Froyo at least. I found application called Easy Call Forwarding.
http://www.appstorehq.com/easycallforwarding-android-189596/app
But many people reckon it doesn't work actually.
We can notice forwarded call by onCallForwardingIndicatorChanged() from PhoneStateListener but
I have no idea how to set forwarding mode.
I explored on the net and got the answer to my question that how one can forward a call programmatically. Add these lines of code and one will be able to achieve it.
String callForwardString = "**21*1234567890#";
Intent intentCallForward = new Intent(Intent.ACTION_DIAL); // ACTION_CALL
Uri uri2 = Uri.fromParts("tel", callForwardString, "#");
intentCallForward.setData(uri2);
startActivity(intentCallForward);
Here 1234567890 represents the phone number. Add the approriate phone number as you wish here. One can dial ##21# to deactivate the service.
My solution:
Intent intent = new Intent(Intent.ACTION_CALL);
String prefix = "#31#";
prefix = Uri.encode(prefix);
intent.setData( Uri.parse("tel:"+prefix+"123456"));
startActivity(intent);

Categories

Resources