0

I'm trying to make refer and earn activity in my app
So I want to permanently display a few apps like whatsapp, etc for the user to click on them and share directly.
I'm using Intent to share the referral code but it pops up the apps list when the user clicks share.
The code I'm using is,

Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "This is a message");
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "Share via"));


How can I make the app chooser permanent for a few apps?

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
Arpit Tomar
  • 53
  • 1
  • 2
  • 6

3 Answers3

0

The app chooser is not intended to be displayed permanently. Therefore you will have to create simple buttons or icons and create an intent that refers to the desired app directly, by setting the package of the intent.

E.g. to share sth with WhatsApp use sth like this:

Intent sendIntent = new Intent();
// here comes the magic
sendIntent.setPackage("com.whatsapp");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);

Depending on the type of content you want to share and the apps you want to share with, it makes sense to reuse the code to create the intent and just set the respective package and eventually some additional parameters.

0

You will need package name of app and a Intent.

  1. change ACTION_VIEW to ACTION_SENDTO
  2. set the Uri as you did set the
  3. package to whatsapp

    Intent i = new Intent(Intent.ACTION_SENDTO,
    Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
    i.setType("text/plain");
    i.setPackage("com.whatsapp");           // so that only Whatsapp reacts and not the chooser
    i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
    startActivity(i);
    

You can refer this link for More:

  1. Send text to specific contact (whatsapp)
  2. Sending message through WhatsApp
Community
  • 1
  • 1
Avinash Verma
  • 2,572
  • 1
  • 18
  • 22
0
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "your text content");
startActivity(intent)

I am facing same problem for share tamil font content in Whatsapp. I found the solution, this setType("*/*") share full content.

Prabhu V
  • 1
  • 2