Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25259] Android: Runtime error "exposed beyond app through Intent.getData()" on API 24 & higher when using Ti.Media.previewImage()

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2018-01-24T21:44:41.000+0000
Affected Version/sRelease 6.2.0
Fix Version/sRelease 7.0.2
ComponentsAndroid
Labelsqe-6.2.0
ReporterLokesh Choudhary
AssigneeGary Mathews
Created2017-09-08T22:17:00.000+0000
Updated2018-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 the TAKE 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()

Expected results:

1. No runtime error should be thrown.

Comments

  1. Gary Mathews 2017-09-11

    master: https://github.com/appcelerator/titanium_mobile/pull/9419
  2. Lokesh Choudhary 2018-01-08

    [~gmathews], Can you please provide a backport.
  3. Lokesh Choudhary 2018-01-08

    FR Passed for master. Waiting for backport.
  4. Gary Mathews 2018-01-08

    7_0_X: https://github.com/appcelerator/titanium_mobile/pull/9703
  5. Lokesh Choudhary 2018-01-10

    FR Passed for backport. Waiting for merge to get enabled for PR's.
  6. Lokesh Choudhary 2018-01-24

    Master PR merged.
  7. Lokesh Choudhary 2018-01-24

    Backport PR merged.
  8. Lokesh Choudhary 2018-01-25

    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

JSON Source