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

Android: Getting an error in the logs when using the Camera (Regression)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Invalid
    • Affects Version/s: Release 5.2.2
    • Fix Version/s: Release 6.1.0
    • Component/s: Android
    • Labels:
      None
    • Story Points:
      3
    • Sprint:
      2017 Sprint 05 SDK

      Description

      Resolving TIMOB-23230 brought attention to this error. Logs as follows:-

      ERROR] :  TiBlob: (main) [449,5770] null
      [ERROR] :  TiBlob: java.io.IOException
      [ERROR] :  TiBlob: 	at java.io.InputStream.reset(InputStream.java:208)
      [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.guessAdditionalContentTypeFromStream(TiBlob.java:239)
      [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.guessContentTypeFromStream(TiBlob.java:214)
      [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.loadBitmapInfo(TiBlob.java:270)
      [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:140)
      [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:113)
      [ERROR] :  TiBlob: 	at ti.modules.titanium.media.TiCameraActivity$3.onPictureTaken(TiCameraActivity.java:563)
      [ERROR] :  TiBlob: 	at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1092)
      [ERROR] :  TiBlob: 	at android.os.Handler.dispatchMessage(Handler.java:102)
      [ERROR] :  TiBlob: 	at android.os.Looper.loop(Looper.java:148)
      [ERROR] :  TiBlob: 	at android.app.ActivityThread.main(ActivityThread.java:5417)
      [ERROR] :  TiBlob: 	at java.lang.reflect.Method.invoke(Native Method)
      [ERROR] :  TiBlob: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
      [ERROR] :  TiBlob: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
      

      This was tested on an Android 6.0, Nexus 6.

      Test code as follows:-

       
      var window = Ti.UI.createWindow();
      var overlay = Ti.UI.createView();
      var button = Titanium.UI.createButton({
          color : '#fff',
          bottom : "10dp",
          width : "130dp",
          height : "50dp",
          font : {
              fontSize : "14dp",
              fontWeight : 'bold',
              fontFamily : 'Helvetica Neue'
          },
          title : 'Take Picture'
      });
       
      button.addEventListener('click', function() {
          Ti.Media.takePicture();
      });
       
      window.add(overlay);
      overlay.add(button);
      window.addEventListener('open', function(e){
         var cameraPermission = "android.permission.CAMERA";
         var storagePermission = "android.permission.READ_EXTERNAL_STORAGE";
         var hasCameraPerm = Ti.Android.hasPermission(cameraPermission);
         var hasStoragePerm = Ti.Android.hasPermission(storagePermission);
         var permissionsToRequest = [];
         if (!hasCameraPerm) {
          permissionsToRequest.push(cameraPermission);
         }
         if (!hasStoragePerm) {
          permissionsToRequest.push(storagePermission);
         }
         if (permissionsToRequest.length > 0) {
          Ti.Android.requestPermissions(permissionsToRequest, function(e) {
              if (e.success) {
                  showCamera();
              } else {
                  Ti.API.info("ERROR: " + e.error);
              }
          });
         } else {
              showCamera();
         }
      });
      Ti.Media.addEventListener('cameraready', function(e){
          Ti.Media.takePicture();
      });
      var container = Ti.UI.createView({
              top:'10%',
              height:'80%'
          });
       
      var img = Ti.UI.createImageView({
          });
       
      container.add(img);
      window.add(container);
      window.open();
       
      function showCamera() {
          Ti.Media.showCamera({
             success : function(e) {
                          Ti.API.info('GOT SUCCESS CALLBACK');
                          var imgWid = e.media.width;
                          var imgHeight = e.media.height;
                          var mSize = container.size;
                          var mW = mSize.width;
                          var mH = mSize.height;
       
                          var wS = imgWid/mW;
                          var hS = imgHeight/mH;
                          var tS = (wS < hS) ? wS : hS;
       
                          var dstWid = imgWid/tS;
                          var dstHeight = imgHeight/ tS;
       
                          Ti.API.info(imgWid+' '+imgHeight+' '+mW+' '+mH+' '+wS+' '+hS+' '+tS+' '+dstWid+' '+dstHeight);
                          var resize = e.media.imageAsResized(dstWid,dstHeight);
                          img.image = resize;
             },
             overlay : overlay,
             mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
             saveToPhotoGallery : true
          });
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                gmathews Gary Mathews
                Reporter:
                msamah Ashraf Abu (Inactive)
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Source Code