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

Android: getting image from Google Drive via openPhotoGallery causes a crash

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Release 7.1.1
    • Component/s: Android
    • Labels:
    • Environment:

      Tested with 6.1.1.GA and 6.2.0.GA.
      Android 7.0

    • Story Points:
      5
    • Sprint:
      2018 Sprint 06 SDK

      Description

      Test project

      index.js:

      function openGallery() {
          Ti.Media.openPhotoGallery({
              mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
              success:function(e) {
                  console.log("\n success");
       
                  var image = Ti.UI.createImageView({
                      image: e.media.imageAsResized(300, 150),
                      width: "150dp",
                      height: "75dp",
                      top: "10dp"
                  });
                  $.win.add(image);
              },
              cancel: function() {
                  console.log("cancel");
              },
              error:function(error) {
                  console.log("error");
              }
          });
      }
       
      function onGallery() {
          if(!Ti.Filesystem.hasStoragePermissions()) {
              Ti.Filesystem.requestStoragePermissions(function(result) {
                  if(result.success) {
                      openGallery();
                  }
              });
          } else {
              openGallery();
          }
      }
       
      $.win.open();
      

      index.xml:

      <Alloy>
      	<Window id='win' backgroundColor="white">
      		<Button bottom="10dp" width="80%" height="50dp" title="Gallery" onClick="onGallery" />
      	</Window>
      </Alloy>
      

      I'm getting error if select image from google drive:

      [WARN]  W/System.err: java.lang.NullPointerException
      [WARN]  W/System.err:   at java.io.File.<init>(File.java:262)
      [WARN]  W/System.err:   at org.appcelerator.titanium.io.TitaniumBlob.getNativeFile(TitaniumBlob.java:138)
      [WARN]  W/System.err:   at org.appcelerator.titanium.TiBlob.getNativePath(TiBlob.java:534)
      [WARN]  W/System.err:   at org.appcelerator.titanium.TiBlob.getImage(TiBlob.java:586)
      [WARN]  W/System.err:   at org.appcelerator.titanium.TiBlob.imageAsResized(TiBlob.java:722)
      [WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)
      [WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57)
      [WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43)
      [WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70)
      [WARN]  W/System.err:   at android.os.Handler.handleCallback(Handler.java:751)
      [WARN]  W/System.err:   at android.os.Handler.dispatchMessage(Handler.java:95)
      [WARN]  W/System.err:   at android.os.Looper.loop(Looper.java:154)
      [WARN]  W/System.err:   at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
      [ERROR] TiExceptionHandler: (main) [18317,18317] ----- Titanium Javascript Runtime Error -----
      [ERROR] TiExceptionHandler: (main) [1,18318] - In /alloy/controllers/index.js:1,358
      [ERROR] TiExceptionHandler: (main) [0,18318] - Message: Uncaught Java Exception occurred
      [ERROR] TiExceptionHandler: (main) [0,18318] - Source: (function (exports, require, module, __filename, __dirname, Titanium, Ti, global, kroll) {function __processArg(a,b){var c=null;return a&&(c=a[b]||null,delete a[b]),c}function Controller(){function a(){Ti.Media.openPhotoGallery({mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],success:function(a){console.log("\n success");var b=Ti.UI.createImageView({image:a.media.imageAsResized(300,150),width:"150dp",height:"75dp",top:"10dp"});c.win.add(b)},cancel:function(){console.log("cancel")},error:function(){console.log("error")}})}function b(){Ti.Filesystem.hasStoragePermissions()?a():Ti.Filesystem.requestStoragePermissions(function(b){b.success&&a()})}require("/alloy/controllers/BaseController").apply(this,Array.prototype.slice.call(arguments)),this.__controllerPath="index",this.args=arguments[0]||{},arguments[0]&&(__processArg(arguments[0],"__parentSymbol"),__processArg(arguments[0],"$model"),__processArg(arguments[0],"__itemTemplate"));var c=this,d={},e={};c.__views.win=Ti.UI.createWindow({id:"win",backgroundColor:"white"}),c.__views.win&&c.addTopLevelView(c.__views.win),c.__views.__alloyId4=Ti.UI.createButton({bottom:"10dp",width:"80%",height:"50dp",title:"Gallery",id:"__alloyId4"}),c.__views.win.add(c.__views.__alloyId4),b?c.addListener(c.__views.__alloyId4,"click",b):e["$.__views.__alloyId4!click!onGallery"]=!0,d.destroy=function(){},_.extend(c,c.__views),"use strict",c.win.open(),e["$.__views.__alloyId4!click!onGallery"]&&c.addListener(c.__views.__alloyId4,"click",b),_.extend(c,d)}var Alloy=require("/alloy"),Backbone=Alloy.Backbone,_=Alloy._;module.exports=Controller;
      [ERROR] V8Exception: Exception occurred at /alloy/controllers/index.js:1: Uncaught Java Exception occurred
      [ERROR] V8Exception: Java Exception occurred
      

      I managed to get around it by:

      file.write(e.media);
      var blob = file.read();
      blob.imageAsResized(); // now you can use this method
      

      P.S. of course, working fine for local images

        Attachments

          Activity

            People

            • Assignee:
              gmathews Gary Mathews
              Reporter:
              zozo4kin Zakhar Zhuravlev
              Reviewer:
              Yordan Banev
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Source Code