Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过Android中的intent向gmail应用程序添加附件_Java_Android_Email_Android Intent_Gmail - Fatal编程技术网

Java 通过Android中的intent向gmail应用程序添加附件

Java 通过Android中的intent向gmail应用程序添加附件,java,android,email,android-intent,gmail,Java,Android,Email,Android Intent,Gmail,我已尝试将附件csv文件添加到邮件意图中。当我启动intent并选择Gmail作为应用程序时,它表示附件的权限被拒绝。我如何解决这个问题 这是我正在使用的代码 try { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("address", input.getText().toString()); editor.apply(); String gmail=sh

我已尝试将附件csv文件添加到邮件意图中。当我启动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文件位于应用程序的私有内部存储中。没有其他应用程序可以访问。只有你的应用。因此,使用过的电子邮件应用程序也无法访问。把文件放在另一个地方。或者使用文件提供程序

文件的“路径”是什么?file path=new Filefile.getAbsolutePathNo,该文件具体驻留在哪里?你是怎么定义路径的?你什么都没告诉我。那么file.getAbsolutePath的值是多少?如果您尝试附加csv文件,那么为什么要使用text/html?我如何使用FileProvider?我已经阅读了Android开发者网站上的文档,但我仍然不太理解@这个问题每周至少被问两次。因此,谷歌或只是阅读一些网页在这里。