android "no applications can perform this action" 使用 "send_multiple",sendto 工作正常
android "no applications can perform this action" using "send_multiple", sendto works fine
我需要将一些文件附加到电子邮件中,但在调用 intent 时出现错误。
如果我使用 Intent.ACTION_SENDTO、选择器 returns Gmail 应用程序和通用电子邮件客户端。但是,如果我尝试将 Intent.ACTION_SEND_MULTIPLE 作为参数传递,我将无法获得能够接收意图的应用程序。我该如何解决?
这是我正在使用的代码。
ArrayList<Uri> attachments = new ArrayList<>();
File path = new File(Environment.getExternalStorageDirectory() + "appFolder");
if (path.exists()){
for (File child : path.listFiles()) {
attachments.add(Uri.fromFile(child));
}
//Intent intent = new Intent(Intent.ACTION_SENDTO);//This works, but I can't attach several files.
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);//This is the part that SHOULD work, but doesn't...
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_SUBJECT, "");
intent.putExtra(Intent.EXTRA_TEXT, "");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
try {
startActivity(Intent.createChooser(intent, "Send Email"));
} catch (ActivityNotFoundException anfe) {
anfe.printStackTrace();
}
}
从删除 intent.setData(Uri.parse("mailto:"));
开始。 ACTION_SEND_MULTIPLE
不使用 setData()
.
然后,去掉intent.putExtra(Intent.EXTRA_TEXT, "");
。不要求任何 ACTION_SEND_*
同时遵守 EXTRA_STREAM
和 EXTRA_TEXT
。由于您没有使用文本,因此如果删除多余的内容,您将获得更可靠的结果。如果你坚持要保留它,你需要使用 put...ArrayListExtra()
,而不是 putExtra()
,因为 ACTION_SEND_MULTIPLE
需要一个数组,而不是单个值。
不过,即使进行了这些更改,您仍然可能无法进行任何活动。很少有应用实现 ACTION_SEND_MULTIPLE
,并且只有一部分应用会支持 message/rfc822
。
我需要将一些文件附加到电子邮件中,但在调用 intent 时出现错误。
如果我使用 Intent.ACTION_SENDTO、选择器 returns Gmail 应用程序和通用电子邮件客户端。但是,如果我尝试将 Intent.ACTION_SEND_MULTIPLE 作为参数传递,我将无法获得能够接收意图的应用程序。我该如何解决?
这是我正在使用的代码。
ArrayList<Uri> attachments = new ArrayList<>();
File path = new File(Environment.getExternalStorageDirectory() + "appFolder");
if (path.exists()){
for (File child : path.listFiles()) {
attachments.add(Uri.fromFile(child));
}
//Intent intent = new Intent(Intent.ACTION_SENDTO);//This works, but I can't attach several files.
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);//This is the part that SHOULD work, but doesn't...
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_SUBJECT, "");
intent.putExtra(Intent.EXTRA_TEXT, "");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);
try {
startActivity(Intent.createChooser(intent, "Send Email"));
} catch (ActivityNotFoundException anfe) {
anfe.printStackTrace();
}
}
从删除 intent.setData(Uri.parse("mailto:"));
开始。 ACTION_SEND_MULTIPLE
不使用 setData()
.
然后,去掉intent.putExtra(Intent.EXTRA_TEXT, "");
。不要求任何 ACTION_SEND_*
同时遵守 EXTRA_STREAM
和 EXTRA_TEXT
。由于您没有使用文本,因此如果删除多余的内容,您将获得更可靠的结果。如果你坚持要保留它,你需要使用 put...ArrayListExtra()
,而不是 putExtra()
,因为 ACTION_SEND_MULTIPLE
需要一个数组,而不是单个值。
不过,即使进行了这些更改,您仍然可能无法进行任何活动。很少有应用实现 ACTION_SEND_MULTIPLE
,并且只有一部分应用会支持 message/rfc822
。