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

Android: previewImage() crashes when given a non-file based blob

    Details

    • Story Points:
      5
    • Sprint:
      2018 Sprint 02 SDK, 2018 Sprint 03 SDK

      Description

      Summary:
      The media.previewImage() method will crash if given a blob whose image is not file based, such as a screenshot returned by View.toImage().

      Steps to Reproduce:

      1. Build and run the below code on an Android device.
      2. Tap the "Preview" button.
      3. Select an app to preview the screenshot, if asked.

      var window = Ti.UI.createWindow();
      var button = Ti.UI.createButton({ title: "Preview" });
      button.addEventListener("click", function(e) {
      	window.toImage(function(imageBlob) {
      		if (!imageBlob) {
      			return;
      		}
      		Ti.Media.previewImage(
      		{
      			image: imageBlob,
      			success: function(e) {
      				Ti.API.info("@@@ Successfully displayed preview.");
      			},
      			error: function(e) {
      				Ti.API.error("@@@ Failed to display preview");
      			},
      		});
      	});
      });
      window.add(button);
      window.open();
      

      Result:
      App crashes with the following stack trace...

      W/System.err( 5003): java.lang.ClassCastException: byte[] cannot be cast to org.appcelerator.titanium.io.TiBaseFile
      W/System.err( 5003): 	at ti.modules.titanium.media.MediaModule.previewImage(MediaModule.java:1148)
      W/System.err( 5003): 	at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
      W/System.err( 5003): 	at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:55)
      W/System.err( 5003): 	at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:41)
      W/System.err( 5003): 	at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:68)
      W/System.err( 5003): 	at android.os.Handler.handleCallback(Handler.java:615)
      W/System.err( 5003): 	at android.os.Handler.dispatchMessage(Handler.java:92)
      W/System.err( 5003): 	at android.os.Looper.loop(Looper.java:137)
      W/System.err( 5003): 	at android.app.ActivityThread.main(ActivityThread.java:4745)
      W/System.err( 5003): 	at java.lang.reflect.Method.invokeNative(Native Method)
      W/System.err( 5003): 	at java.lang.reflect.Method.invoke(Method.java:511)
      W/System.err( 5003): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
      W/System.err( 5003): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
      W/System.err( 5003): 	at dalvik.system.NativeStart.main(Native Method)
      

      Expected Result:
      Should not crash. Should either display the in-memory image or invoke the error callback stating that the given blob must be file based. Ideally, the given memory based blob should be stored to a temp file and displayed.

      Work-Around:
      Titanium developer can save the blob to a temp file and preview the file instead.

      Note:
      The following pending PR will fix the "TiBaseFile" exception mentioned in the above stack trace...
      https://github.com/appcelerator/titanium_mobile/pull/9223

      However, the Java code proceeding the image.getData() method call in MediaModule.previewImage() still needs to be changed to handle a blob that'll return a null for its native file path.
      https://github.com/appcelerator/titanium_mobile/blob/7_0_X/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L1148

        Attachments

          Activity

            People

            • Assignee:
              gmathews Gary Mathews
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Yordan Banev
              Tester:
              Samir Mohammed
            • Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-6054
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code