Error while sending ZIP file via Intent on Android

Asked

Viewed 34 times

1

I am trying to send a ZIP file via Intent on Android with the code below:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(out));
sendIntent.setType("application/zip");
startActivity(sendIntent);

But I can only send if it is via Whatsapp, other apps like Gmail, Outlook, Onedrive or Google Drive return errors like "could not attach/send the file".

I’ve modified Intent’s last line to:

startActivityForResult(sendIntent, ZIP_OK);

Where ZIP_OK = 101;

In:

@Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)

The resultCode returns to 0 (zero) if not via Whatsapp.

Does anyone know what I haven’t done, or what I’m doing wrong?

1 answer

1


To share a file you need to pass a URI with reference to its location, you can try:

Uri.fromFile(File file)

or

FileProvider.getUriForFile(Context context, String authority, File file)

Documentation:

  • It worked, thank you very much!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.