我尝试将附件(csv 文件)添加到邮件 Intent 中。当我启动 Intent 并选择 Gmail 作为应用程序时,它会显示“附件的权限被拒绝”。我该如何解决这个问题?
这是我正在使用的代码
try {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("address", input.getText().toString());
editor.apply();
String gmail=sharedPreferences.getString("address","");
Uri dat = Uri.fromFile(path);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/html");
sendIntent.putExtra(Intent.EXTRA_EMAIL, gmail);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Stuff");
sendIntent.putExtra(Intent.EXTRA_STREAM, dat);
startActivity(Intent.createChooser(sendIntent, "Send email..."));
}catch (Exception e){
System.out.println(e.toString());
}
最佳答案
您的 csv 文件位于应用程序的私有(private)内部存储中。没有其他应用程序可以访问。只有您的应用程序。因此使用的电子邮件应用程序也无法访问。将文件放在另一个地方。或者使用 FileProvider。
关于java - 在 Android 中通过 Intent 将附件添加到 Gmail 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43668728/