Titanium JIRA Archive
Appcelerator Community (AC)

[AC-4967] Selecting a photo (Ti.Media.openPhotoGallery) on Google Pixel (API 25) crashes immediately

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2017-05-18T13:26:11.000+0000
Affected Version/sAppcelerator Studio 4.5.0
Fix Version/sn/a
ComponentsTitanium SDK & CLI
LabelsTi.Media.openPhotoGallery, android
ReporterCameron
AssigneeShak Hossain
Created2017-05-17T02:49:33.000+0000
Updated2017-05-18T13:26:11.000+0000

Description

The code snippet below successfully opens the photo gallery. However, once a photo(s) is selected, the app immediately crashes. No error message in the console. Just the generic Android message of "myApp keeps stopping" This bug does not seem to affect other devices with API 24 or 23. No specific pattern discovered yet, except that it definitely crashes on the Google Pixel API 25 emulator and the real device.
Ti.Media.openPhotoGallery({
        allowMultiple: true,
 
        success: function(e) {
          Ti.API.info(JSON.stringify(e));
        },
        cancel: function() { },
        error: function() { }
    });

Comments

  1. Cameron 2017-05-17

    Sorry, for some reason the system doesn't let me post issues to TIMOB. Only to either Appcelerator - Inbox or Aptana Studio. Not sure if that is by design, but if I made a mistake in where to file this, my appologies
  2. Sharif AbuDarda 2017-05-17

    Hello, Are you providing the storage permission during run-time? Try using the below code.
       var cameraPermission = "android.permission.CAMERA";
       
       var storagePermission = "android.permission.READ_EXTERNAL_STORAGE";
       
       var hasCameraPermission = Ti.Android.hasPermission(cameraPermission);
       
       var hasStoragePermission = Ti.Android.hasPermission(storagePermission);
       
       var permissionsToRequest = [];
       
       if (!hasCameraPermission) {
       
           permissionsToRequest.push(cameraPermission);
       
       }
       
       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);
       
               }
       
           });
       
       }
       var win = Titanium.UI.createWindow();
       
       var btn = Ti.UI.createButton({
       
           title : 'Open Gallery',
           top : 10
       
       });
       
       var imageView = Ti.UI.createImageView({
           top : 100,
           height : 200,
           weidth : 200
       });
       win.add(imageView);
       
       btn.addEventListener('click', function() {
       
           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));
       
               }
           });
       
       });
       
       win.add(btn);
       
       win.open();
       
    Tiapp.xml in Android section.
                   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
                   <uses-permission android:name="android.permission.CAMERA"/>
       
    Thanks.
  3. Cameron 2017-05-18

    Ok well, you are a genius. Sorry I didn't know about these permissions. That solved it!

JSON Source