gpt4 book ai didi

android - 选择某些应用程序出现在共享选择器中

转载 作者:行者123 更新时间:2023-11-30 03:11:49 25 4
gpt4 key购买 nike

我有一个按钮可以分享到我的应用程序的链接;但是这个按钮显示了 skype、gmail、whatsapp...例如,我怎样才能只显示 whatsapp?我能做什么?

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

我的意思是我知道如何选择应用程序,例如 whatsapp: Sending message through WhatsApp

但是我如何选择多个应用程序..谢谢。

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

最佳答案

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

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

我有几个应用程序的类名和 Activity 名。我可以提供。试试这些,我会修改答案。

关于android - 选择某些应用程序出现在共享选择器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20826052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com