2016-09-11 10 views
0

目标:当用户点击按钮Send to...,我希望Android应用程序打开,可以发送邮件(邮件,短信等)的列表。用户选择一个。这种应用的文本消息中已经喂打开Android的意图:通过电子邮件或短信发送消息时,使用内置的应用程序选择器

下面是我用它来尝试实现这一代码:

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setType("text/plain"); 
intent.putExtra(Intent.EXTRA_TEXT, outputTextView.getText()); 
if (intent.resolveActivity(getPackageManager()) != null) { 
    startActivity(intent); 

问题:当运行它,正确地显示可用的应用程序列表(如Gmail,环聊,Messenger,保留,翻译等)。如果我选择GMail,它工作正常。 但是:如果我选择环聊,保留,翻译或任何其他建议的应用程序,我的文本不会显示在这些应用程序中。

我错过了什么?

回答

2

试试这个代码

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); 
     shareIntent.setType("text/plain"); 
     shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Try this code for Sharing!"); 
     shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I'm trying to share data...."); 

     Intent chooserIntent = Intent.createChooser(shareIntent, "Share with"); 
     chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     startActivity(chooserIntent); 
+0

你的代码的工作比我在创造avalaible应用程序的功能更强大的列表更好。在你的版本中,我需要用'outputTextView.getText()'替换字符串“我试图共享数据....”,我必须附加'.toString()'。我原来的代码缺少'toString'调用。我的解决方案和我的解决方案都能达到我所说的目标。所以我正在接受你的答案。 –

+1

是的,你可以很容易地通过替换该行来做到这一点。很高兴它可以帮助你..谢谢.. –

相关问题