Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25541] Android: Use ContentProvider in EmailDialog #9520

Merged
merged 12 commits into from Jan 10, 2018

Conversation

alg
Copy link
Contributor

@alg alg commented Oct 11, 2017

JIRA:

Summary:

  • Fixes bug where EmailDialog fails to attach files on Android 7.0 and higher.
  • Fixes bug where EmailDialog fails to attach files in Microsoft Outlook, regardless of Android OS version.
  • Fixed by using Titanium's new content provider by switching file attachment URI schemes from "file:" to "content:".

Test:

  1. Set up a project using the test code attached to TIMOB-25541.
  2. Build and run on an Android 7.0 or newer device.
  3. Tap on the "Send E-Mail" button.
  4. Select the "GMail" app if asked.
  5. Verify that 2 files are attached: "File1.txt" and "File2.txt"
  6. Install and set up Microsoft "Outlook" on the device, if not already.
  7. Repeat steps 2-5 above, but choose "Outlook" for step 4 instead.

The same issue with file URI's being sent directly is fixed by replacing direct URI's with content provider URIs.
@hansemannn
Copy link
Collaborator

Thank you!

@build
Copy link
Contributor

build commented Oct 11, 2017

Messages
📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

@jquick-axway
Copy link
Contributor

@alg, thanks for catching this issue.

This is definitely the right solution. However, the code needs 1 more change. In the EmailDialogProxy.buildIntent(), you need to add read permission to the intent like below. Otherwise, e-mails apps will fail to read the file on Android 7.0 or higher if your app targets API Level 24 or higher.

intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

@build build added the android label Nov 17, 2017
@hansemannn
Copy link
Collaborator

@jquick-axway @lokeshchdhry This may have fallen behind because the JIRA references a 6.3.0 fix-version. Should we get this in for 7.0.0? Thanks @sgtcoolguy for the review!

@jquick-axway
Copy link
Contributor

From looking at the code again, I'm pretty sure attachments will still fail on Android 7.0 and higher. We would have to test it to be sure, but I think the prepareAttachments() method needs to be modified to pass attachments via the Intent.setClipData() method instead of EXTRA_STREAM. This is because the FLAG_GRANT_READ_URI_PERMISSION flag is only applied to the intent's URI and clip data.

This requires a bit of experimentation. I can look into it later. I wrote up a separate ticket to make sure this isn't forgotten here...
https://jira.appcelerator.org/browse/TIMOB-25541

@jquick-axway jquick-axway changed the title [TIMOB-25363] Android: Use ContentProvider in EmailDialog [TIMOB-25541] Android: Use ContentProvider in EmailDialog Nov 27, 2017
@sgtcoolguy sgtcoolguy modified the milestones: 7.0.0, 7.1.0 Nov 30, 2017
…s to attach files on Android 7.0 and higher.

Also done the following:
- Now falls-back to writing to sandboxed temp directory if unable to write to external storage.
- Improved error log message when blobs failed to attach.
@jquick-axway jquick-axway removed their request for review November 30, 2017 23:41
Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS

@lokeshchdhry
Copy link
Contributor

FR Passed

Verified on android 8.0, 7.1.1, 6.0.1, 4.4.2

For https://jira.appcelerator.org/browse/TIMOB-23482:

  1. Clicking on send Email open up the chooser.
  2. If Outlook is installed & selected it opens up the email dialog.
  3. The 2 attachments File1.txt & 'File2.txt` are attached successfully.
  4. The recipients & message body are seen as well.

For https://jira.appcelerator.org/browse/TIMOB-25541:

  1. On android 7.0 & above, clicking on send Email open up the chooser.
  2. If Outlook is installed & selected it opens up the email dialog.
  3. The 2 attachments File1.txt & 'File2.txt` are attached successfully.
  4. The recipients & message body are seen as well.
  5. Same is seen for Gmail.

Studio Ver: 5.0.0.201712081732
SDK Ver: 7.1.0 local build
OS Ver: 10.13.2
Xcode Ver: Xcode 9.2
Appc NPM: 4.2.11
Appc CLI: 7.0.1
Daemon Ver: 1.0.1
Ti CLI Ver: 5.0.14
Alloy Ver: 1.10.10
Node Ver: 8.9.1
NPM Ver: 5.5.1
Java Ver: 1.8.0_101
Devices: ⇨ google Pixel --- Android 7.1.1
⇨ google Nexus 5 --- Android 6.0.1
Emulators: Android 8.0, 4.4.2

@lokeshchdhry lokeshchdhry merged commit 407c17c into tidev:master Jan 10, 2018
@alg alg deleted the patch-2 branch January 11, 2018 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants