How to share text to WhatsApp from my app?
How to share text to WhatsApp from my app?
I develop an app with a functionality for sharing text. This is working fine except for WhatsApp. What should I do? Is there any specific API for that?
9 Answers
9
There is no public official api for whats app....So it is not possible now.
it is possible with Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setPackage("com.whatsapp"); intent.putExtra(Intent.EXTRA_TEXT, "some text"); activity.startActivity(intent);
– Muhammad Adil
Mar 22 '16 at 7:29
Do not post an answer if you do not know !
– Bhavik Mehta
Jun 4 '16 at 11:33
Saqqib is answered on 6-Nov-2012.. Please check the answered date and time before giving down vote and comments.
– jfalexvijay
Jun 29 '16 at 8:38
Do not post an answer if you do not know about it...
– A.A
Oct 13 '16 at 16:09
You can use intent to do so.
No need to use Whatsapp API.
Hope that I have not misunderstood your question. Hope that helps, thanks.
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.");
This is perfect code. Its worked for me and Yes marked answer saving its not possible that is completely wrong. This answer should be marked as Correct answer.
– Ghanshyam Nayma
Oct 26 '16 at 11:33
Perfect, works for me.
– CodeSlave
Nov 5 '17 at 12:53
I'm an Android developer, how can I integrate WhatsApp with my app?
– Eido95
Nov 8 '17 at 21:58
There are two ways to integrate with WhatsApp:
Through a custom URL scheme
Through Android's intent system.
If you have a website and want to open a WhatsApp chat with a pre-filled message, you can use our custom URL scheme to do so. Opening whatsapp://send?text= followed by the text to send, will open WhatsApp, allow the user to choose a contact, and pre-fill the input field with the specified text.
Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
However, if you prefer to share directly to WhatsApp and bypass the system picker, you can do so by using setPackage in your intent:
sendIntent.setPackage("com.whatsapp");
This would simply be set right before you call startActivity(sendIntent);
Please refer below link Official WhatsApp Page:
https://www.whatsapp.com/faq/en/android/28000012,
If you want to share some text to specific WhatsApp contact, Please refer below code.
private void openWhatsApp()
String smsNumber = "7****"; //without '+'
try
Intent sendIntent = new Intent("android.intent.action.MAIN");
//sendIntent.setComponent(new ComponentName("com.whatsapp", "com.whatsapp.Conversation"));
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.putExtra("jid", smsNumber + "@s.whatsapp.net"); //phone number without "+" prefix
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
catch(Exception e)
Toast.makeText(this, "Error/n" + e.toString(), Toast.LENGTH_SHORT).show();
For more details please refer below link
Send text to specific contact (whatsapp)
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted.
– FelixSFD
Apr 7 '17 at 14:25
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
– EJoshuaS
Apr 7 '17 at 15:40
Edited my ans @EJoshuaS
– Jitendra Kumar. Balla
Apr 7 '17 at 17:55
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "Your text");
startActivity(Intent.createChooser(share, "Share using"));
Please add some explanation to your answer. Code-only answers are discouraged on SO. Thank you.
– Gennadii Saprykin
Jul 18 '16 at 16:11
I am not 100% sure...but i am afraid there is no official API released. I also wanted to implement a "send us a whatsapp" feature, but i am giving up for a while until whatsapp.inc release a official one
There are some no-official API but i do not know if you want that...
http://www.whatsapp-api.com/developers.php
https://github.com/venomous0x/WhatsAPI
good luck....and if you discover something, please let me know ;)
Thanks.........but I have already tried this
– user1755441
Nov 6 '12 at 9:23
yes there is:faq.whatsapp.com/en/android/28000012
– Alon Kogan
Mar 12 at 16:31
i think this page is deleted from whatspp website
– E-housma Mardini
Apr 16 at 9:55
You can use the WhatsApp API
Android: http://www.whatsapp.com/faq/en/android/28000012
iOS: http://www.whatsapp.com/faq/en/iphone/23559013
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
If user's device does not have the Whatsapp app then you got the ActivityNotFoundException
If the user does not have the whatsapp App in their device,then i
think you have to do user's move to the download whatsapp from play
store
public void shareViaWhatsApp()
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, "Application of social rating share with your friend");
try
Objects.requireNonNull(getActivity()).startActivity(whatsappIntent);
catch (android.content.ActivityNotFoundException ex)
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.whatsapp")));
message = "this msg is sent from My App Time Track"
val intent = Intent()//Empty as we don't know the destination i.e implicit intent
intent.action = Intent.ACTION_SEND//intent will do work of sending something
intent.putExtra(Intent.EXTRA_TEXT, message)//send given message
intent.putExtra(Intent.EXTRA_SUBJECT,"Download Time Track App")//give the subject for your message
//Intent.Extra_Text is actually a globol key
intent.type = "plane/text"//type of intent
startActivity(Intent.createChooser(intent,"Send to: "))//createChooser is a dialogBox which shows app available to send data
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Use Android’s sharing mechanism. I can share text just fine with WhatsApp.
– poke
Nov 5 '12 at 17:38