When I'm trying to share text using intent mechanism and pick WhatsApp, it says:
Can't send empty message
I've read an official docs about Android integration here: https://faq.whatsapp.com/en/android/28000012
My code:
public void shareText(String label, CharSequence title, CharSequence body) {
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, title.toString());
intent.putExtra(Intent.EXTRA_TEXT, TextUtils.concat(title, body));
final Intent chooser = Intent.createChooser(intent, label);
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (chooser.resolveActivity(mContext.getPackageManager()) != null) {
mContext.startActivity(chooser);
}
}
Am I doing something wrong? Or is it bug with WhatsApp messenger?
P.S. arguments title
and body
are not empty in my case.
Press the key your phone uses for "Space." On some phones, this is "0," whereas others have their own "Space" or "Space Bar'' key.
To work around this problem, you can use the blank character on this page. It is seen as a character different than space, but it looks the same. You can use it to send a invisible message, or set your WhatsApp status to empty. WhatsApp does not allow to send a blank messages using spaces.
What you have done is,
intent.putExtra(Intent.EXTRA_TEXT, TextUtils.concat(title, body));
while TextUtils.concat(title, body)
returns CharSequence
probably that whatsapp does not support.
You have to pass the value as a String leaving you two solutions.
intent.putExtra(Intent.EXTRA_TEXT, TextUtils.concat(title, body).toString());
String someValue = TextUtils.concat(title, body).toString();
and adding it here as,
intent.putExtra(Intent.EXTRA_TEXT, someValue);
Here You can send data from your app to Whatsapp
and any other like a messenger
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, " Your text ");
startActivity(Intent.createChooser(share, " Your text "));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With