1

I have a button that shares the link to my app; but this button shows skype, gmail, whatsapp... how can I only show whatsapp for example? what can I do?

Plus when sending a mail I need to choose only gmail and hotmail for example how to do that?

I mean I know how to choose an app such as whatsapp: Sending message through WhatsApp

but how can I choose several apps.. thanks.

Edit Does someone have a tutorial on how to create your own share chooser? thanks.

Community
  • 1
  • 1
Learning Android
  • 273
  • 4
  • 17
  • You can't. On Android, the user is in control of which apps respond to which Intents and which apps are defaults, if any, for those intents. The user gets to choose, not you. – Simon Dec 29 '13 at 14:38
  • Yeah I know thank you. But I meant how can I set the whatsapp for example as the receiving app take a look at: http://stackoverflow.com/questions/15462874/sending-message-through-whatsapp please so I know how to select one app but I need to select several.. – Learning Android Dec 29 '13 at 14:41

1 Answers1

1

Create your own chooser and use the following codes:

public void share_on_gmail()
{
    Intent sharingIntent = is_intent_available("com.google.android.gm",
            "com.google.android.gm.ComposeActivityGmail", "Gmail");

    send_mail(sharingIntent);
}

public void share_on_yahoo()
{
    Intent sharingIntent = is_intent_available("com.android.email",
            "com.android.email.activity.MessageCompose", "Email");

    send_mail(sharingIntent);
}

public void share_on_facebook()
{
    Intent sharingIntent = is_intent_available("com.facebook.katana",
                    "com.facebook.katana.ShareLinkActivity", "Facebook");
}

public void share_on_twitter()
{
    Intent sharingIntent = is_intent_available("com.twitter.android",
                            "com.twitter.android.PostActivity", "Twitter");

    if (sharingIntent != null)
    {
        String subject = ((XmlNewsDetailsParser)xmlParser).subject;
        String body = ((XmlNewsDetailsParser)xmlParser).body;
        File  mFile = savebitmap(((Picture)itemsAdapter.getItem(0)).image.bitmap);
        sharingIntent.setType("image/png");
        sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mFile));
        sharingIntent.putExtra(Intent.EXTRA_TEXT, "القارئ العربي" + "\n\n" + subject + "\n\n" + Html.fromHtml(body));

        startActivity(sharingIntent);
    }
}

public Intent is_intent_available(final String className, String activityName, String appName)
{
        Intent I = new Intent(android.content.Intent.ACTION_SEND);
        if (!activityName.equals(""))
        {
            I.setClassName(className, activityName);
        }
        else
        {
            I.setPackage(className);
        }

        PackageManager packageManager = getPackageManager();
        List list = packageManager.queryIntentActivities(I, PackageManager.MATCH_DEFAULT_ONLY);

        if (list==null || list.size() == 0)
        {
            AlertDialog ad = new AlertDialog.Builder(this).create();
            ad.setMessage("Please install the " + appName + " app to share news with your friends.");
            ad.setButton2("Later", new DialogInterface.OnClickListener() {  
                @Override  
                public void onClick(DialogInterface dialog, int which) {  
                    dialog.dismiss();
                }
            });

            ad.setButton("Install Now", new DialogInterface.OnClickListener() {  
                @Override  
                public void onClick(DialogInterface dialog, int which) {  
                    Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=" + className));
                    startActivity(marketIntent);
                }
            });  
            ad.show();
            return null;
        }
        return I;
}

public void send_mail(Intent sharingIntent)
{
    if (sharingIntent == null) return;
    String subject = ((XmlNewsDetailsParser)xmlParser).subject;
    String body = ((XmlNewsDetailsParser)xmlParser).body;
    File  mFile = savebitmap(((Picture)itemsAdapter.getItem(0)).image.bitmap);
    sharingIntent.setType("image/png");
    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, subject + "القارئ العربي - ");
    sharingIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mFile));
    startActivity(sharingIntent);
}

I have the class name and the activity name for a couple of more applications. I can provide it. Try those and I will modify the answer.

hasan
  • 23,815
  • 10
  • 63
  • 101
  • thank you very much hasan but will this permit me to use several apps for example open a chooser where there is: whatsapp, gmail and hotmail as choices or this will just permit me to choose one app? – Learning Android Dec 29 '13 at 15:15
  • the chooser by default choose apps that can be used to share with the content you provided. but, as I understood from your question you want some of those apps to appear in some case and others to appear in other case. that's want work unless you create your own chooser(window you create that contain the apps depending on content). in this case you must handle it using the code in the answer. – hasan Dec 29 '13 at 15:19
  • as you can see I don't show the app chooser here. because I want to customize the apps that appear in a window I create (those apps will be different depending on situation). therefore, I need a way to share directly without showing chooser window because I implemented mine. when user choose from my chooser. I share depending on what he choose. trance the facebook example in you want. – hasan Dec 29 '13 at 15:23
  • Ok I will later. got to go home. – hasan Dec 29 '13 at 16:07
  • yeah but couldn't know how to use it because didn't understand what going on in the code so didn't work but I am sure that it's a good answer and will mark it as the solution as soon as it works.. so will retry it later and will try to find out how the code is working.. – Learning Android Dec 30 '13 at 12:49