【问题标题】:Add attachment to gmail app via intent in Android通过 Android 中的意图将附件添加到 gmail 应用程序
【发布时间】:2017-09-25 21:28:41
【问题描述】:

我已尝试向邮件意图添加附件(csv 文件)。当我启动意图并选择 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());
}

【问题讨论】:

  • 文件的“路径”是什么?
  • 文件路径=新文件(file.getAbsolutePath())
  • 不,这个文件到底在哪里?你如何定义path
  • 你告诉我注意。那么 file.getAbsolutePath() 的值是什么?
  • 如果你尝试附加一个 csv 文件,那你为什么要使用 text/html 呢?

标签: java android email android-intent gmail


【解决方案1】:

您的 csv 文件位于应用的私有内部存储中。没有其他应用程序可以访问。只有你的应用程序。因此,使用过的电子邮件应用程序也无法访问。把文件放在另一个地方。或者使用 FileProvider。

【讨论】:

  • 我该如何使用 FileProvider?我已经阅读了 Android Developers 网站上的文档,但我仍然不太明白。 @greenappps
  • 这个问题每周至少被问两次。所以谷歌或只是在这里阅读一些页面。
猜你喜欢
  • 1970-01-01
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 2015-03-20
  • 1970-01-01
相关资源
最近更新 更多