Reputation: 1741
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.
Upvotes: 6
Views: 4849
Reputation: 36
Here sendEmtpyMassages is Button Just copy this method It's Work for you
sendEmtpyMassages.setOnClickListener {
val context: Context = applicationContext
val sendIntent = Intent("android.intent.action.MAIN")
sendIntent.action = Intent.ACTION_VIEW
sendIntent.setPackage("com.whatsapp")
val url = "https://api.whatsapp.com/send?phone=" + "&text=" + " "
sendIntent.data = Uri.parse(url)
if (sendIntent.resolveActivity(context.packageManager) != null) {
startActivity(sendIntent)
}
}
Upvotes: 0
Reputation: 1675
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);
Upvotes: 10
Reputation: 882
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 "));
Upvotes: 1