Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19910] Android: openPhotoGallery fails when remote image selected

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-04-14T20:52:58.000+0000
Affected Version/sRelease 5.0.2
Fix Version/sRelease 5.4.0
ComponentsAndroid
LabelsCommunity
ReporterManuel Lehner
AssigneeAshraf Abu
Created2015-10-02T14:33:35.000+0000
Updated2016-12-20T03:40:53.000+0000

Description

Comments

  1. Amimul Hossain 2015-10-04

    Hello [~manuellehner], I have tested this issue with SDK 5.0.0.GA, 5.0.1.GA. The issue is seems to be resolved. Environment TI SDK 5.0.0.GA, 5.0.1.GA CLI 5.0.2 Android 5.0.2, Galaxy A5. Below is the output log when a particular image is opened and selected from "gallery".
       [INFO] :   event.media.nativePath: file:///storage/emulated/0/DCIM/Camera/20150930_223405.jpg
       [INFO] :   event.media.file.nativePath: content://media/external/images/media/38175
       
    And, Here is the output log when that particular image is opened and selected from "google photos".
       [INFO] :   event.media.nativePath: file:///storage/emulated/0/DCIM/Camera/20150930_223405.jpg
       [INFO] :   event.media.file.nativePath: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F38175/ACTUAL/1431804670
       
    Both are performed simultaneously one after another. No Java exception occurred. Thanks.
       var win = Titanium.UI.createWindow({
       
       	backgroundColor : '#fff',
       
       	layout : 'vertical'
       
       });
       
        
       
       var camera = Ti.UI.createButton({
       
       	backgroundColor : '#ff0000',
       
       	title : 'Open Gallery',
       
       	color : '#fff',
       
       	width : Ti.UI.SIZE,
       
       	height : Ti.UI.SIZE,
       
       	top : 30
       
        
       
       });
       
        
       
       camera.addEventListener('click', function() {
       
       	openGallery();
       
       	//rear();
       
       });
       
        
       
       // Create an ImageView.
       
       var addPreviewImage = Ti.UI.createImageView({
       
       	image : 'location',
       
       	width : 200,
       
       	height : 200,
       
       	top : 20,
       
       });
       
        
       
       // Add to the parent view.
       
       win.add(camera);
       
       win.add(addPreviewImage);
       
        
       
       function openGallery() {
       
       	Titanium.Media.openPhotoGallery({
       
       		success : function(event) {
       
       			if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
       
       				addPreviewImage.setImage(event.media);
       
       				try {
       
       					Ti.API.info('event.media.nativePath: ' + event.media.nativePath);
       
       				} catch(e) {
       
       					Ti.API.error(e.message);
       
       				}
       
       				Ti.API.info('event.media.file.nativePath: ' + event.media.file.nativePath);
       
        
       
       			} else {
       
       				//alert("got the wrong type back =" + event.mediaType);
       
       			}
       
       		},
       
       		cancel : function() {
       
       			// called when user cancels taking a picture
       
       		},
       
       		error : function(error) {
       
       			// called when there's an error
       
       			var a = Titanium.UI.createAlertDialog({
       
       				title : 'Camera'
       
       			});
       
       			if (error.code == Titanium.Media.NO_CAMERA) {
       
       				a.setMessage('Please run this test on device');
       
       			} else {
       
       				a.setMessage('Unexpected error: ' + error.code);
       
       			}
       
       			a.show();
       
       		},
       
       		allowEditing : true,
       
       		mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
       
       	});
       
       }
       
        
       
       win.open();
       
    Thanks.
  2. Manuel Lehner 2015-10-05

    [~ahossain] Thanks for testing. I've just tested this again with your example code with 4.1.0.GA and 5.0.0.GA - but I was able to reproduce this error (testing on a Nexus 5). I've selected two images from Google Photos, first one stored on the device, works fine:
       [INFO] :   event.media.nativePath: file:///storage/emulated/0/DCIM/Camera/IMG_20151002_095208.jpg
       [INFO] :   event.media.file.nativePath: content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F105558/ACTUAL/688518979
       
    The second image is not on the device, it loads the file from the cloud and then shows this log:
       [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:185)
       [WARN] :   W/System.err: 	at java.io.File.<init>(File.java:134)
       [WARN] :   W/System.err: 	at org.appcelerator.titanium.io.TitaniumBlob.getNativeFile(TitaniumBlob.java:97)
       [WARN] :   W/System.err: 	at org.appcelerator.titanium.TiBlob.getNativePath(TiBlob.java:529)
       [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:135)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
       [ERROR] :  Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
       [INFO] :   event.media.file.nativePath: content://com.google.android.apps.photos.contentprovider/0/1/mediaKey%3A%2FAF1QipPIihdsteNy0HTCR2MVdCdbjTTNvt10V_lMHKJL/ACTUAL/404242549
       
    Although it shows the image in the preview, I'm not able to upload the Blob to my server which works fine for locally stored images.
  3. Sharif AbuDarda 2015-11-09

    Hello [~manuellehner], I have observed the similar issue with SDK 5.0.2.GA. In Android 4.4.2 Device, when a photo is selected from Google Photos and if the photo is not existing in device the image first downloads and loads into the image view. In addition to that the following error occur.
       [WARN] :   W/System.err: java.lang.NullPointerException
       [WARN] :   W/System.err: 	at java.io.File.fixSlashes(File.java:185)
       [WARN] :   W/System.err: 	at java.io.File.<init>(File.java:134)
       [WARN] :   W/System.err: 	at org.appcelerator.titanium.io.TitaniumBlob.getNativeFile(TitaniumBlob.java:97)
       [WARN] :   W/System.err: 	at org.appcelerator.titanium.TiBlob.getNativePath(TiBlob.java:529)
       [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:808)
       [WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:103)
       [WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:193)
       [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)
       [ERROR] :  Java Exception occurred
       [INFO] :   event.media.file.nativePath: content://com.google.android.apps.photos.contentprovider/0/1/mediaKey%3A%2FAF1QipMz-KZetA16ZU5d4QOrSTvC0tOyhrEP5NeVnQqN/ACTUAL/1594537096
       
    Thanks.
  4. Ashraf Abu 2015-12-07

    [~manuellehner] Which Android version were you using? Was it Android 6.0?
  5. Manuel Lehner 2015-12-07

    Yes, Android 6.0, but I remember having the same problem with Android 5.x
  6. Filipe La Ruina 2016-02-25

    Hi, I'm having the same problem. I found out that this is a problem with native code as well. See this: http://stackoverflow.com/questions/24573640/android-error-upload-image-in-different-android-versions I've confirmed that this is an issue with the photos app, when selecting media that is available on the cloud. Is it possible to work around the issue using the DocumentsProvider API as stated in the answer from the link?
  7. Ashraf Abu 2016-04-01

    [~filaruina] I see. Thank you for that link. Are you using that natively (DocumentsProvider)?
  8. Filipe La Ruina 2016-04-01

    No, I just limited this functionality on my app, which is terrible, but while appcelerator doesn't give us a solution, I'll have to live with that.
  9. Ashraf Abu 2016-04-04

    PR https://github.com/appcelerator/titanium_mobile/pull/7911
  10. Ashraf Abu 2016-04-15

    PR merged.
  11. Filipe La Ruina 2016-04-15

    Thanks! Will wait for the update and try it.
  12. Lokesh Choudhary 2016-06-28

    Verified the fix. openPhotoGallery does not fail when remote image is selected. Closing. Environment: Appc Studio : 4.7.0.201606150733 Ti SDK : 5.4.0.v20160617074028 Ti CLI : 5.0.9 Alloy : 1.9.0 MAC El Capitan : 10.11.4 Appc NPM : 4.2.7-2 Appc CLI : 5.4.0-18 Node: 4.4.4 Nexus 6 - Android 6.0.1
  13. David Fox 2016-12-15

    Is anyone else getting this error when using openPhotoGallery with SDK 6.0.0? I started getting it all of a sudden and gallery image selection became completely broken.
  14. Rohit Khanna 2016-12-20

    Hello, Even i got this error yesterday working on SDK 6.0.0. If I assign the "e.media" to my imageView.image property is does display the image but as soon as I try and explore the "e.media", either to extract e.media.nativePath or even JSON.Stringify(e.media), it gives me this error. Any guidance , highly appreciated. Cheers
  15. David Fox 2016-12-20

  16. Rohit Khanna 2016-12-20

    Thanks David, :) I will follow the progress there.. Cheers

JSON Source