[TIMOB-25439] Android: Intent extra 'file://' URI not working on Android 7 or higher
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-10-30T20:27:58.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.3.0 |
Components | Android |
Labels | Android, File, Intent |
Reporter | Jorge Macias Garcia |
Assignee | Gary Mathews |
Created | 2017-10-24T11:26:34.000+0000 |
Updated | 2018-05-16T22:49:59.000+0000 |
Description
Affects 6.2.2, 6.3.X on Android 8.
It works on Android 7 and 7.1
Android N sets a new restriction in the use of URIs. It must be a Content URI instead a file URI. In that case, if we try to share some file throught nativePath it fails.
Steps:
Read some file in your app (be sure it is placed in the external storage), after that try to share it via intent chooser:
var file = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'example.pdf');
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_SEND,
type: file.read()
.getMimeType()
});
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
//In this point nativePath is 'file://' URI. It will throw the exception
intent.putExtraUri(Ti.Android.EXTRA_STREAM, file.nativePath);
var chooser = Ti.Android.createIntentChooser(intent, 'Share');
$.win.activity.startActivity(chooser);
Attachments
File | Date | Size |
---|---|---|
image-2017-10-24-13-21-26-117.png | 2017-10-24T11:21:27.000+0000 | 37577 |
IntentActionSendTest.js | 2017-10-27T00:30:59.000+0000 | 720 |
This has been addressed here: https://github.com/appcelerator/titanium_mobile/pull/9559
The attached [^IntentActionSendTest.js] script can be used to test Intent.putExtraUri() content provider access.
master: https://github.com/appcelerator/titanium_mobile/pull/9559 6_3_X: https://github.com/appcelerator/titanium_mobile/pull/9566
FR passed for both master & backport PR's. Backport PR merged. Waiting for master merge to get enabled.
Verified the fix with SDK 6.3.0.v20171030135813. Studio Ver: 4.10.0.201709271713 OS Ver: 10.12.3 Xcode Ver: Xcode 8.3.3 Appc NPM: 4.2.10-2 Appc CLI: 6.3.0-master.15 Ti CLI Ver: 5.0.14 Alloy Ver: 1.10.6 Node Ver: 7.10.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 6P --- Android 8.0.0 ⇨ google Nexus 5 --- Android 6.0.1
Master PR merged. Closing.