[TIMOB-25259] Android: Runtime error "exposed beyond app through Intent.getData()" on API 24 & higher when using Ti.Media.previewImage()
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-01-24T21:44:41.000+0000 |
Affected Version/s | Release 6.2.0 |
Fix Version/s | Release 7.0.2 |
Components | Android |
Labels | qe-6.2.0 |
Reporter | Lokesh Choudhary |
Assignee | Gary Mathews |
Created | 2017-09-08T22:17:00.000+0000 |
Updated | 2018-01-25T00:00:29.000+0000 |
Description
*Reason:* https://inthecheesefactory.com/blog/how-to-share-access-to-file-with-fileprovider-on-android-nougat/en
Steps to reproduce:
1. Use the code below in the app.js:
if (Ti.Media.hasCameraPermissions()) {
win.open();
} else {
Ti.Media.requestCameraPermissions(function(e) {
if (e.success === true) {
Ti.API.info("Camera Permissions Granted");
win.open();
} else {
alert("Access denied, error: " + e.error);
}
});
}
var win = Ti.UI.createWindow({backgroundColor: 'grey'});
win.add(Ti.UI.createLabel({
backgroundColor : "blue",
color : "yellow",
text : "Hello There",
textAlign : "center",
left : "10dp",
right : "10dp",
top : "5dp",
height : "40dp"
}));
win.add(Ti.UI.createImageView({
height : "43dp",
width : "46dp",
image : "KS_nav_ui.png",
top : "100dp"
}));
var btn;
win.add( btn = Ti.UI.createButton({
title : "Take screenshot",
bottom : "5dp",
height : "40dp",
left : "50dp",
right : "50dp"
}));
function previewCallback(args) {
Ti.API.info("previewImage success");
}
function previewError(e) {
alert("previewImage failure: " + e.message);
Ti.API.error(e.message);
}
function screenshotCallback(image) {
if (!image) {
alert("Eeks, takeScreenshot didn't return anything.");
return;
} else {
var blob = image.media;
if (!blob) {
alert("Eeks, there was no useful 'media' member of the passed result dictionary.");
return;
}
if (Ti.Platform.osname === "android") {
Ti.API.info("Got an image blob back from takeScreenshot. Gonna store it and preview it.");
var tempdir = Ti.Filesystem.tempDirectory;
var file = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, "temp.png");
if (file.exists()) {
file.deleteFile();
}
file.write(blob);
Ti.Media.previewImage({
success : previewCallback,
error : previewError,
image : file.read()
});
} else {
alert("Call to takeScreenshot successful. Got a blob back.");
}
}
}
btn.addEventListener("click", function() {
Ti.Media.takeScreenshot(screenshotCallback);
});
win.add(btn);
2. Make sure you have camera
permission in your tiapp.xml:
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<uses-permission android:name="android.permission.CAMERA"/>
</manifest>
</android>
2. Build the app to android device.
3. After the app launches, click on TAKE SCREENSHOT
.
Actual result:
1. On API 24 & higher clicking theTAKE SCREENSHOT
button causes Runtime Error
:
[ERROR] : [Pixel] TiExceptionHandler: (main) [1069017,2565939] ----- Titanium Javascript Runtime Error -----
[ERROR] : [Pixel] TiExceptionHandler: (main) [0,2565939] - In /acceptance.js:4015,14
[ERROR] : [Pixel] TiExceptionHandler: (main) [0,2565939] - Message: Uncaught file:///storage/emulated/0/com.appcelerator.MediaModule/temp.png exposed beyond app through Intent.getData()
[ERROR] : [Pixel] TiExceptionHandler: (main) [0,2565939] - Source: Ti.Media.previewImage({
[ERROR] : [Pixel] V8Exception: Exception occurred at /acceptance.js:4015: Uncaught file:///storage/emulated/0/com.appcelerator.MediaModule/temp.png exposed beyond app through Intent.getData()
[ERROR] : [Pixel] V8Exception: file:///storage/emulated/0/com.appcelerator.MediaModule/temp.png exposed beyond app through Intent.getData()
master: https://github.com/appcelerator/titanium_mobile/pull/9419
[~gmathews], Can you please provide a backport.
FR Passed for master. Waiting for backport.
7_0_X: https://github.com/appcelerator/titanium_mobile/pull/9703
FR Passed for backport. Waiting for merge to get enabled for PR's.
Master PR merged.
Backport PR merged.
Verified the fix with SDK 7.1.0.v20180124153334 & 7.0.2.v20180124142857. Closing. Studio Ver: 5.0.0.201712081732 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: ⇨ samsung SM-G955U1 --- Android 7.0 ⇨ google Nexus 5 --- Android 6.0.1