1

我有一个按钮可以共享我的应用程序的链接;但是这个按钮显示Skype,gmail,whatsapp......我怎么能只显示whatsapp?我能做些什么?

另外,在发送邮件时,我只需要选择 gmail 和 hotmail,例如如何做到这一点?

我的意思是我知道如何选择诸如whatsapp之类的应用程序: 通过WhatsApp发送消息

但我怎样才能选择几个应用程序.. 谢谢。

编辑 有人有关于如何创建自己的共享选择器的教程吗?谢谢。

4

1 回答 1

1

创建您自己的选择器并使用以下代码:

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);
}

我有更多应用程序的类名和活动名。我可以提供。试试这些,我会修改答案。

于 2013-12-29T15:07:01.490 回答