没有默认启动的意图ACTION_SEND

时间:2016-03-24 20:05:33

标签: android android-intent

我试图通过我的应用在意图中使用ACTION_SEND共享文本。但是,如果您选择使用默认的应用程序,它将与相同的应用程序共享,而不是每次都询问。

有人可以帮我吗?

如果它可行,它应该能够通过邮件,脸书,推特,whatsapp分享这样的代码。感谢。

Intent textShareIntent = new Intent(Intent.ACTION_SEND);
            textShareIntent.putExtra(Intent.EXTRA_TEXT, "Text to share, URL");
            textShareIntent.setType("text/plain");
            startActivity(textShareIntent);

1 个答案:

答案 0 :(得分:12)

试试这个

Intent textShareIntent = new Intent(Intent.ACTION_SEND);
textShareIntent.putExtra(Intent.EXTRA_TEXT, "Text to share, URL");
textShareIntent.setType("text/plain");
if (textShareIntent.resolveActivity(getPackageManager()) != null)
    startActivity(Intent.createChooser(textShareIntent, "Share"));
else
    // no app can handle this intent, do something else
相关问题