element-hq / element-android

A Matrix collaboration client for Android.
https://element.io/
GNU Affero General Public License v3.0
3.39k stars 732 forks source link

EXTRA_TEXT is ignored when receiving EXTRA_STREAM Intent #3637

Open eighthave opened 3 years ago

eighthave commented 3 years ago

Describe the bug

An app can create an ACTION_SEND Intent to share a file and/or text to another app. This Intent can provide an InputStream to get the actual file via EXTRA_STREAM. This Intent can also include EXTRA_TEXT to describe what the shared file is. Apps like K-9Mail, Gmail, Signal, etc. correctly handle this case and include both the file itself and the related text in the draft message. Element only attaches the file and ignores the text.

This is used in F-Droid to share apps. The text is the name/description of the app and the URL that points to the app's page on f-droid.org. The EXTRA_STREAM is the actual APK if available. Having all together means that the user can choose to share a message or the actual APK, depending on the receiving app.

To Reproduce

  1. Create an Intent and open the Share chooser.
  2. Select Element

Here's the code for creating the Share chooser:

        Intent intent = new Intent(Intent.ACTION_SEND);
        Uri streamUri = getUri(context, packageName); // points to ContentProvider in F-Droid
        // the streamUri could be any file that's easy to include, e.g. an image
        intent.setType("application/zip");
        intent.putExtra(Intent.EXTRA_STREAM, streamUri);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra(Intent.EXTRA_SUBJECT, "Shared from F-Droid: " + app.name + ".apk");
        intent.putExtra(Intent.EXTRA_TITLE, app.name + ".apk");
        String extraText = String.format("%s (%s)\nhttps://f-droid.org/packages/%s/",
                app.name, app.summary, app.packageName);
        intent.putExtra(Intent.EXTRA_TEXT, extraText);
        Intent chooserIntent = Intent.createChooser(intent, getString(R.string.menu_share));
        startActivity(chooserIntent);

This feature will also be included in F-Droid v1.14, go to Settings --> Manage installed apps --> Click on an app --> Click share.

Expected behavior

Should create a draft message with the text from EXTRA_TEXT with the data in EXTRA_STREAM there as an attachment.

Screenshots

Screenshot_20210706-120943 Screenshot_20210706-121441

FYI @n8fr8

More info and discussion

bmarty commented 3 years ago

I agree, this is not ideal. We should probably use the body to send the EXTRA_TEXT content, but currently there is no way to edit the body of an Event with a m.file attachment, and the spec recommends to use the filename here...