Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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
Android 通过Intent.ACTION\u SEND共享文件时,Google drive将文件名更改为Intent.EXTRA\u SUBJECT_Android_Android Intent_Google Drive Android Api - Fatal编程技术网

Android 通过Intent.ACTION\u SEND共享文件时,Google drive将文件名更改为Intent.EXTRA\u SUBJECT

Android 通过Intent.ACTION\u SEND共享文件时,Google drive将文件名更改为Intent.EXTRA\u SUBJECT,android,android-intent,google-drive-android-api,Android,Android Intent,Google Drive Android Api,我有以下代码通过Intent.ACTION\u SEND共享文件。最后一行显示选择器,以便用户可以选择适当的应用程序。当我选择电子邮件时,一切都很好,文件已附加到电子邮件。另一方面,当我选择Google drive时,文件会上载到Google drive,但文件名会更改为备份,这是主题。也就是说,如果我调用shareBackup/sdcard/001.mks,那么Google驱动器上的文件名是Backup而不是001.mks。我的代码有问题吗 public void shareBackup(St

我有以下代码通过Intent.ACTION\u SEND共享文件。最后一行显示选择器,以便用户可以选择适当的应用程序。当我选择电子邮件时,一切都很好,文件已附加到电子邮件。另一方面,当我选择Google drive时,文件会上载到Google drive,但文件名会更改为备份,这是主题。也就是说,如果我调用shareBackup/sdcard/001.mks,那么Google驱动器上的文件名是Backup而不是001.mks。我的代码有问题吗

public void shareBackup(String path) {  
    String to = "YourEmail@somewhere.com";
    String subject = "Backup";
    String message = "Your backup is attached";
    Intent email = new Intent(Intent.ACTION_SEND);
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, message);
    File f = new File(path);
    email.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));       
    email.setType("text/*");
    startActivity(Intent.createChooser(email, "Send"));     
}

我也遇到了这个问题,我发现的一个解决方法是使用action Intent.action\u SEND\u MULTIPLE而不是Intent.action\u SEND来共享文件。在这种情况下,共享文件在与google drive共享时会保留其名称。注意:我不理解为什么会存在此问题,或者随着时间的推移,此“修复”是否会继续工作。在寻找这个问题的解决方案时,我只遇到了这篇未答复的SO帖子,没有找到任何现有的bug报告,也没有花时间亲自提交。所以,希望这篇文章能帮助一些人

请注意,当为intent提供文件Uri时,必须使用intent.putParcelableArrayListExtra而不是intent.putExtra,并将单个Uri包装在ArrayList中

通过这些更改,上述代码应该如下所示:

public void shareBackup(String path) {  
    String to = "YourEmail@somewhere.com";
    String subject = "Backup";
    String message = "Your backup is attached";
    Intent email = new Intent(Intent.ACTION_SEND_MULTIPLE);
    email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    email.putExtra(Intent.EXTRA_SUBJECT, subject);
    email.putExtra(Intent.EXTRA_TEXT, message);
    File f = new File(path);
    email.putParcelableArrayListExtra(Intent.EXTRA_STREAM, new ArrayList<>(Arrays.asList(Uri.fromFile(f))));       
    email.setType("text/*");
    startActivity(Intent.createChooser(email, "Send"));     
}

您能否显示在选择Google Drive时如何处理传入的意图?最后一行显示android选择器。然后,我选择谷歌驱动器。之后,谷歌驱动器应用程序显示,上传继续从谷歌驱动器应用程序不是我的。在这一步中,将显示一个标题为“保存到驱动器”的对话框,我只需在谷歌驱动器上选择一个文件夹,然后按下“保存”按钮。文件已成功上载到驱动器。当我使用Google Drive应用程序将文件下载到SD卡时,文件名是Backup而不是001.mks。我的意思是关于如何处理意图的代码,因为错误可能就在那里。我也遇到过同样的问题。Google Drive将主题作为文件名,因此如果你不想将文件名放在主题中,你就完蛋了。像个魔咒一样工作!!