This is a migrated thread and some comments may be shown as answers.

.getPicture Android Fail

11 Answers 179 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
KC
Top achievements
Rank 2
KC asked on 26 Aug 2014, 09:25 PM
Greetings,

    I have an application that requires the user to either select a photo or take a picture and then upload that photo to a web service. IPhone, works fine, Android, no go. 
The errors I get with Android are,
Camera -> Camera Cancelled,
Gallery -> Selection cancelled.

This error pops up even before the Camera/Gallery opens, they open, but it has already failed so it is pointless. The simulator does not catch this. I have not been able to test it on other Android devices, but the one I know it is braking with is: Droid Maxx.

Code Below:


var cur = SAMPLE.models.testOneOne;
        $('#getPic').click(function () {
            navigator.camera.getPicture(
            function () {
                alert('Success')
            },
            function (message) {
                alert('Fail: ' + message);
            }, {
                saveToPhotoAlbum: false,
                quality: 10,
                destinationType: destinationType.FILE_URI,
                sourceType: 0,
                encodingType: 0,
                mediaType: 0,

            });
        })

11 Answers, 1 is accepted

Sort by
0
Zdravko
Telerik team
answered on 29 Aug 2014, 11:52 AM
Hello Keith,

Thanks for contacting us.
I tried to reproduce your issue using our sample app on Nexus 4 Android 4.3, but of no avail. The API was working fine.

Would you try whether you will experience the same with our sample?

Regarding your app, I suggest debugging it on the device as described here and try it on another device if possible.
Furthermore, you can use an emulator and debug there for example to access the gallery.

If you need additional assistance I will be glad to help.

Regards,
Zdravko
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
KC
Top achievements
Rank 2
answered on 03 Sep 2014, 04:00 PM
OK,

So, I was able to finally get the project loaded on the Droid X that we have, pain in the butt by the way, and it works just fine on it. Both the little test app and the actual application that this feature is used in.

As far as additional information on the Droid MAXX:
System Version: 21.11.21.obake-maxx)verizon.Verizon.en.US
System Information: Motorola X8 Mobile Computing System
Android Version: 4.4.4
Baseband version: MSM8960PRO_BP_232.55.52.00R
Kernal Version: 3.4.42-gb33f23d
hdsplat@ca101Inxdroid70 #1

I guess, as far as I can tell, it is just not compatible with this phone.

I have this tracked in a support ticket, but I will keep this line open in case they find an answer/workaround on that end so I can share it here.
0
Kaloyan
Telerik team
answered on 08 Sep 2014, 01:37 PM
Hi KC,

I am closing this thread for now. You can reopen it at any time, by replying/posting in it. I suggest we continue the discussion in your support ticket on the same matter and update this thread after a solution is found.

Regards,
Kaloyan
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
Jeff
Top achievements
Rank 1
answered on 06 Oct 2015, 08:44 AM
I am having ta similar issue. The camera will take picture,but tmy app will quit w
0
Jeff
Top achievements
Rank 1
answered on 06 Oct 2015, 08:53 AM
sorry for the typos since  your app here doesn't let me see what I am typing
0
Jeff
Top achievements
Rank 1
answered on 06 Oct 2015, 08:56 AM
 I am having a similar issue. The camera will take picture,but my app will quit without any error trace
0
Dimitrina
Telerik team
answered on 08 Oct 2015, 12:13 PM
Hello Jeff,

I am sorry to hear you have hit a similar issue when taking picture.

Testing the scenario on my side, I am afraid I could not observe any problem - the picture is taken and displayed on the device as expected.

In order to be able to advice you further, may I ask you to share some additional information:
- Do you experience the same with the Camera Sample?
- Are there any specific errors listed if you try Debugging on Device
- Does the issue occur on a specific mobile OS or on any?
- Would you try running the app on a different Android device just so we can rule out the exact device module as a cause?

Looking forward to hearing from you.

Regards,
Dimitrina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
Jeff
Top achievements
Rank 1
answered on 11 Oct 2015, 01:39 AM

Hi Dimitrina,

The phone will simple kill my application after I click the check mark after selecting the picture from the Camera or the Photo Library.


It's probably not the problem of Cordova plugin, rather it's the problem of the phone itself.  I deployed the app from tutorial https://ccoenraets.github.io/cordova-tutorial/handlebars-templates.html and the camera worked. After a month the camera doesn't work on this project either.  


Following are my code:
=============Controller
  var getImage = function(){
    console.log(msg+"getImage - start");

    CameraService.getPicture(options).then(
      function(res){
        console.log(msg+"getImage success with res:");
        // $scope.member.face = "Jeff_Wang.jpg";
        if(res==="" ||res===undefined){
          showTipMsg();
          console.log(msg+"getImage, success res='"+res+"' -- image unchanged");
        }
        else{
          vm.member.face="data:image/jpeg;base64,"+res;
          picDirty=true;
          checkDirty();
          console.log(msg+"getImage, success image.length:"+res.length);
        }

      }
      ,function(err){   
        showTipMsg();   
        console.err(msg+"getImage with error: "+err+" -- use original image: "+vm.member.face);
      }


=================Services
.factory('CameraService', function(CameraNotAvailable,CameraAvailable) {
   var msg = "services - .factory('CameraService')::: ";
  if (navigator.camera) {
    console.log(msg+"has camera");
    return CameraAvailable;
  } else {
    console.log(msg+"has NO camera")
    return CameraNotAvailable;
  }
})




.service('CameraAvailable',['$q', function($q) {
   var msg = "service('CameraAvailable'::: ";
   console.log(msg+"Start");
  return {
    getPicture: function(options) {
      var q = $q.defer();


      navigator.camera.getPicture(function(result) {
        // Do any magic you need
        q.resolve(result);
        console.log(msg+"resolve");
      }, function(err) {
        console.log(msg+"err");
        q.reject(err);
      }, options);


      return q.promise;
    }
  }
}])

I tried to debug it and the debugger stopped at following line with null:  org.apache.cordova.CordovaInterfaceImpl

public void setActivityResultCallback(CordovaPlugin plugin) {
// Cancel any previously pending activity.
if (activityResultCallback != null) {
activityResultCallback.onActivityResult(activityResultRequestCode, Activity.RESULT_CANCELED, null);
}
activityResultCallback = plugin;   *********** activityResultCallback  = null here
}

0
Dimitrina
Telerik team
answered on 14 Oct 2015, 11:39 AM
Hello Jeff,

Have you eventually checked the "Don't keep activities" option in developer option menu of your phone? If so, please unselect it. Also, would you confirm you distribute and install the app on the device and not test it in the AppBuilder Companion App?

Since the behavior replicates on your side, you can try :
- using the adb tool that comes with the Android SDK to examine the device logs. They should have captured the exact error causing the app to crash. 
- running the app on a different Android device just so we can rule out the exact device module as a cause. 

In case the issue still persists, would you please send us the sample app as you are testing on, so that I can verify the exact case on my side?

Looking forward to hearing from you.

Regards,
Dimitrina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
0
Jeff
Top achievements
Rank 1
answered on 16 Oct 2015, 02:47 PM

Hi Dimitrina,

 The un-check on the Don't keep activities option fixed the problem.  I can take pictures using the app.

 Thanks very much!

0
Caio
Top achievements
Rank 1
answered on 21 Sep 2016, 04:46 PM
Man, if i was a women i go to ur house now and kiss u a lot, tnks.
Tags
Apache Cordova
Asked by
KC
Top achievements
Rank 2
Answers by
Zdravko
Telerik team
KC
Top achievements
Rank 2
Kaloyan
Telerik team
Jeff
Top achievements
Rank 1
Dimitrina
Telerik team
Caio
Top achievements
Rank 1
Share this question
or