Google Drive changes Intent.EXTRA_SUBJECT file name when sharing a file through Intent.ACTION_SEND

I have the following code to share a file through Intent.ACTION_SEND. The last line displays the selection so that the user can select the appropriate application. When I selected the letter, everything is in order, and the file is attached to the letter. On the other hand, when I select a Google drive, the file is uploaded to the Google drive, but the file name changes to “backup”, which is the subject. That is, if I call shareBackup("/sdcard/001.mks"), then the file name on the Google Drive “Backup” is not “001.mks”. Are there any problems with my code?

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"));     
}
+4
1

, , , Intent.ACTION_SEND_MULTIPLE Intent.ACTION_SEND . Google ( : , , "" . SO, , . , , ).

, Uris 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"));     
}
+2

Source: https://habr.com/ru/post/1628652/


All Articles