Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24256] Android: openPhotoGallery is not working at all on SDK 6.0.0.GA,6.0.1.GA

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-01-23T14:09:07.000+0000
Affected Version/sRelease 6.0.0
Fix Version/sRelease 6.0.2
ComponentsAndroid
Labelsn/a
ReporterDavid Fox
AssigneeGary Mathews
Created2016-12-15T07:26:02.000+0000
Updated2017-05-05T12:23:07.000+0000

Description

I can't get openPhotoGallery to work on Android since upgrading to 6.0.0. The gallery opens fine, but when an image is selected, and I try to read the blob, I'm getting the following error:
[WARN] :   W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
[WARN] :   W/System.err:    at java.io.File.fixSlashes(File.java:183)
[WARN] :   W/System.err:    at java.io.File.<init>(File.java:130)
[WARN] :   W/System.err:    at org.appcelerator.titanium.io.TitaniumBlob.getFile(TitaniumBlob.java:77)
[WARN] :   W/System.err:    at org.appcelerator.titanium.TiBlob.getLength(TiBlob.java:364)
[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:739)
[WARN] :   W/System.err:    at android.os.Handler.dispatchMessage(Handler.java:95)
[WARN] :   W/System.err:    at android.os.Looper.loop(Looper.java:148)
[WARN] :   W/System.err:    at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)
[WARN] :   EGL_emulation: eglSurfaceAttrib not implemented
[WARN] :   OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xdc79b4e0, error=EGL_SUCCESS
[ERROR] :  TiExceptionHandler: (main) [20134,28149] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,28149] - In undefined:230,23
[ERROR] :  TiExceptionHandler: (main) [0,28149] - Message: Uncaught Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
[ERROR] :  TiExceptionHandler: (main) [1,28150] - Source:       if (me.attachedImage.length > 5242880) {
[WARN] :   EGL_emulation: eglSurfaceAttrib not implemented
[WARN] :   OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe8e3e9a0, error=EGL_SUCCESS

Comments

  1. Sharif AbuDarda 2016-12-15

    Hello, Please send the sample code for us to test.
  2. David Fox 2016-12-18

    I'm using:
       var params = {
          mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
          allowEditing: false,
          success: photoSelected
       };
       
       var photoSelected = function(e) {
          // e.media.file.name has the name of the file but trying to access the actual content of the file blob causes the error to be thrown
       }
       Ti.Media.openPhotoGallery(params);
       
  3. David Fox 2016-12-19

    I did some more tests with this. I created a brand new project and tested Ti.Media.openPhotoGallery. While I don't get the error, it just doesn't seem to work at all. None of the callbacks get called when the image is selected. Are you able to get any calls to Ti.Media.openPhotoGallery on Android 6 with SDK 6.0 to work at all? I haven't been able to.
  4. Sharif AbuDarda 2016-12-20

    Hi, I have tested the issue. The galary opens fine as expected. See my code
       var win1 = Ti.UI.createWindow({
           backgroundColor : 'blue',
           title : 'Blue'
       });
       
       var button = Titanium.UI.createButton({
           title : 'Hello',
           top : 10,
           width : 100,
           height : 50
       });
       button.addEventListener('click', function(e) {
           Titanium.API.info("You clicked the button");
           Ti.Media.openPhotoGallery({
               mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
               success : function(e) {
                   imageView.image = e.media;
               },
               cancel : function() {
               },
               error : function(e) {
                   Ti.API.error(JSON.stringify(e));
               }
           });
       
       });
       
       win1.add(button);
       
       var imageView = Ti.UI.createImageView({
           top : 100,
           width : 200,
           height : 500
       
       });
       win1.add(imageView);
       
       win1.open();
       
    You have to call openPhotoGallery in an event listener. Thanks.
  5. David Fox 2016-12-20

  6. Sharif AbuDarda 2016-12-21

    Hello, I am testing in Android 6.0.1. Try using my code structure and modify it to your need. Now, The JIRA link you provide the issue is different than your issue and that's already fixed. Hello, We will test your issue when we have the full reproducible sample code. Thanks.
  7. Rohit Khanna 2016-12-22

    Dear Sharif, Can you please modify the 'success' section to below: and see if you can manage to read any property of 'e.media'. success : function(e) { imageView.image = e.media; console.log(e.media); // or console.log(JSON.Stringify(e.media)); }, Thanks
  8. David Fox 2016-12-22

    Yeah, I just tested, and while Sharif's example works, it does not work when you try to do anything with e.media aside from just sticking it in an ImageView. Like Rohit points out, that example will fail because of the console.log erroring out trying to work with e.media. You also can't do anything like e.media.length which is very important functionality.
  9. Gary Mathews 2016-12-29

    master: https://github.com/appcelerator/titanium_mobile/pull/8716
  10. Samir Mohammed 2017-01-10

    Verified fix, using the test case provided by [~gmathews] in https://github.com/appcelerator/titanium_mobile/pull/8716. Was able to open the gallery and insert a picture in to the application without any error provided permissions were set as stated in the test case.
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        
    *Environment*
        Appcelerator Command-Line Interface, version 6.1.0
        Nexus 6p (Android 7.1)
        Operating System Name: Mac OS X El Capitan
        Operating System Version: 10.11.6
        Node.js Version: 4.6.0
        npm: 4.2.8
        Titanium SDK Version: 6.1.0.v20170110133045
        Xcode: 8.2
        Appcelerator Studio: 4.8.1.201612050850
        
  11. Eric Merriman 2017-01-20

    Reopening to add version and to allow back port.
  12. David Fox 2017-01-21

    Would this fix be included in the latest 6.1.0 build from http://builds.appcelerator.com? If so, at least in the Android emulator, the bug is still occurring for me. I'm testing in Genymotion Samsung Galaxy S7 running Android 6.0.0. The same crash occurs. Everything seems fine when the Titanium SDK is switched to 5.x.
  13. Hans Knöchel 2017-01-23

    PR (6_0_X): https://github.com/appcelerator/titanium_mobile/pull/8774 [~dfoxinator] Can you give us some more infos, an example project and the logs you get (even when they are the same)? Thx!
  14. Samir Mohammed 2017-01-24

    Verified fix for 6.0.2 backport, using the test case provided by Gary Mathews in https://github.com/appcelerator/titanium_mobile/pull/8716. Was able to open the gallery and insert a picture in to the application without any error provided permissions were set as stated in the test case. *Environment*
        Appcelerator Command-Line Interface, version 6.1.0
        Nexus 6p (Android 7.1)
        Operating System Name: Mac OS X El Capitan
        Operating System Version: 10.11.6
        Node.js Version: 4.6.0
        npm: 4.2.8
        Titanium SDK Version: 6.0.2.v20170123140026
        Xcode: 8.2
        Appcelerator Studio: 4.8.1.201612050850
        
  15. David Fox 2017-01-26

    Hey, I did some more testing. On an Android device running Android 6.0, the fix seems to work. However, on the Genymotion Samsung Galaxy S7 Android 6.0.0 device, the same error occurs after selecting an image: [ERROR] : TiExceptionHandler: (main) [0,14815] - Message: Uncaught Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference However, on the Google Nexus 6P Android 7.0.0 emulator, selecting an image works. Have you tested this in an emulator running Android 6? Thanks.
  16. Samir Mohammed 2017-01-26

    Hey [~dfoxinator] I tested the application on two 6.0.0 devices (Genymotion Samsung Galaxy S7 and Genymotion Samsung Galaxy S6) and i was able to open the photo gallery and select an image without any errors as long as permissions were set. Could you provide some more information? Thanks. *Environment*
        Appcelerator Command-Line Interface, version 6.1.0
        Genymotion Samsung Galaxy S7 6.0.0
        Genymotion Samsung Galaxy S6 6.0.0
        Operating System Name: Mac OS X El Capitan
        Operating System Version: 10.11.6
        Node.js Version: 4.6.0
        npm: 4.2.8
        Titanium SDK Version: 6.0.2.v20170123140026
        Xcode: 8.2
        Appcelerator Studio: 4.8.1.201612050850
        
    *Note* Used <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> in the xml file *Code used to tested with*
        var w = Ti.UI.createWindow({
        	backgroundColor : 'grey'
        }),
            b = Titanium.UI.createButton({
        	title : 'OPEN GALLERY',
        	top : '10dp'
        }),
            iv = Ti.UI.createImageView({
        	top : '65dp',
        	width : '95%'
        });
        
        b.addEventListener('click', function(e) {
        
        	var storagePermission = "android.permission.READ_EXTERNAL_STORAGE";
        	var hasStoragePermission = Ti.Android.hasPermission(storagePermission);
        	var permissionsToRequest = [];
        	if (!hasStoragePermission) {
        		permissionsToRequest.push(storagePermission);
        	}
        	if (permissionsToRequest.length > 0) {
        		Ti.Android.requestPermissions(permissionsToRequest, function(e) {
        			if (e.success) {
        				Ti.API.info("SUCCESS");
        			} else {
        				Ti.API.info("ERROR: " + e.error);
        			}
        		});
        	}
        
        	Ti.Media.openPhotoGallery({
        		mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
        		success : function(e) {
        			iv.height = e.media.height * (iv.rect.width / e.media.width);
        			iv.image = e.media;
        
        			alert(e.media.file.name);
        			alert(e.media.length);
        		},
        		error : function(e) {
        			Ti.API.error(JSON.stringify(e));
        		}
        	});
        });
        
        w.add(b);
        w.add(iv);
        
        w.open();
        
  17. Lokesh Choudhary 2017-02-02

    Closing the issue as fixed.
  18. Netto Ramalho 2017-03-01

    Hi guys I'm having this problem, only when I select an image from the gallery in the download category. External read permissions are enabled. *Environment: Nexus 5X 7.1.1*
        Operating System
          Name                        = Mac OS X
          Version                     = 10.11.6
          Architecture                = 64bit
          # CPUs                      = 4
          Memory                      = 8589934592
        
        Node.js
          Node.js Version             = 4.6.2
          npm Version                 = 2.15.11
        
        Titanium CLI
          CLI Version                 = 5.0.9
        
        Titanium SDK
          SDK Version                 = 6.0.2.GA
          SDK Path                    = /Users/netoramalho/Library/Application Support/Titanium/mobilesdk/osx/6.0.2.GA
          Target Platform             = android
        
    *Console*
        [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.getFile(TitaniumBlob.java:101)
        [WARN]  W/System.err: 	at org.appcelerator.titanium.TiBlob.getLength(TiBlob.java:364)
        [WARN]  W/System.err: 	at org.appcelerator.titanium.TiBlob.getBytes(TiBlob.java:327)
        [WARN]  W/System.err: 	at ti.modules.titanium.network.TiHTTPClient.addTitaniumFileAsPostData(TiHTTPClient.java:866)
        [WARN]  W/System.err: 	at ti.modules.titanium.network.TiHTTPClient.send(TiHTTPClient.java:1036)
        [WARN]  W/System.err: 	at ti.modules.titanium.network.HTTPClientProxy.send(HTTPClientProxy.java:148)
        [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)
        
  19. Samir Mohammed 2017-03-01

    I am able to reproduce this error when selecting an image from downloads only. *Environment*
        Appcelerator Command-Line Interface, version 6.1.0
        Nexus 6p (Android 7.1)
        Operating System Name: Mac OS X El Capitan
        Operating System Version: 10.11.6
        Node.js Version: 4.6.0
        npm: 4.2.8
        Titanium SDK Version: 6.0.2.GA
        Xcode: 8.2
        Appcelerator Studio: 4.8.1.201612050850
        
  20. David Fox 2017-04-27

    Is there an update on this? This issue is definitely not fixed and shouldn't be closed.

JSON Source