Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25409] Android: getting image from Google Drive via openPhotoGallery causes a crash

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-03-22T21:34:18.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.1.1
ComponentsAndroid
Labelsandroid, blob, gallery
ReporterZakhar Zhuravlev
AssigneeGary Mathews
Created2017-09-18T11:54:42.000+0000
Updated2018-03-23T11:28:10.000+0000

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

Comments

  1. Sharif AbuDarda 2017-10-18

    I was able to reproduce the issue with SDK 6.2.2.GA. App crash only when selecting image from Google drive, From Google photo it's ok. And also on the local image.
  2. Hani Hamadeh 2018-02-21

    Waiting for this fix too
  3. Gary Mathews 2018-03-06

    master: https://github.com/appcelerator/titanium_mobile/pull/9906
  4. Lokesh Choudhary 2018-03-21

    [~gmathews], Can you please provide a backport.
  5. Lokesh Choudhary 2018-03-21

    FR passed for master PR.
  6. Lokesh Choudhary 2018-03-21

    Master PR merged.
  7. Lokesh Choudhary 2018-03-22

    FR Passed for backport PR. PR merged.
  8. Samir Mohammed 2018-03-23

    Verified in SDK Version 7.1.1.v20180322144031 and 7.2.0.v20180322112525. Test and other information can be found at: 7_1_X: https://github.com/appcelerator/titanium_mobile/pull/9954 Master: https://github.com/appcelerator/titanium_mobile/pull/9906

JSON Source