Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-25259

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: None
    • Resolution: Fixed
    • Affects Version/s: Release 6.2.0
    • Fix Version/s: Release 7.0.2
    • Component/s: Android
    • Labels:
    • Environment:
    • Story Points:
      5
    • Sprint:
      2017 Sprint 19 SDK

      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.

        Attachments

          Activity

            People

            • Assignee:
              gmathews Gary Mathews
              Reporter:
              lchoudhary Lokesh Choudhary
              Reviewer:
              Joshua Quick
              Tester:
              Lokesh Choudhary
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Source Code