Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share text with WhatsApp on Android "Can't send empty message"

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.

like image 863
Oleksandr Albul Avatar asked Aug 13 '19 08:08

Oleksandr Albul


People also ask

How do you send blank messages on android?

Press the key your phone uses for "Space." On some phones, this is "0," whereas others have their own "Space" or "Space Bar'' key.

How do you write a blank message?

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.


2 Answers

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.

  • You can convert the whole to a String by toString()

intent.putExtra(Intent.EXTRA_TEXT, TextUtils.concat(title, body).toString());

  • Converting it a String before passing it to intent.

String someValue = TextUtils.concat(title, body).toString();

and adding it here as,

intent.putExtra(Intent.EXTRA_TEXT, someValue);
like image 87
sanjeev Avatar answered Nov 15 '22 03:11

sanjeev


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 "));
like image 38
BlackBlind Avatar answered Nov 15 '22 04:11

BlackBlind