Forced termination when selecting an image with an Android app using cordova

Asked 2 years ago, Updated 2 years ago, 104 views

I am working on creating an app for the first time.
I'm trying to use cordova as an Android app for web views.

"I have created a function that allows me to ""select photos and images"" and register them."
If you select a photo or image from a source other than Photo Gallery (e.g., GoogleDrive, Download, Dropbox),
The application will be terminated.

The build was done on Android Studio.

If anyone knows anything about it, please tell me how to solve it.
Put the code you created below.Thank you for your cooperation.

Source code (*Assume: cordova.js is loaded)

  • HTML portion
<div class="photo-open"><p>Photo selection</p><div>
<div class="photo"></div>
  • JavaScript portion
$(function(){ 
  // Gallery Selection 
  $('.photo-open').on('click', function(){ 
    takeFromGallery(); 
  }); 

  function takeFromGallery() { 
    varonSuccess=function(imageData){ 
      // preview display 
      $('.photo') .attr('src', 'data:image/jpeg; base64, '+imageData); 
    }; 

    getPictureFromGallery(onSuccess); 
  } 

  vargetPictureFromGallery=function(onSuccess){ 
    var options = { 
      quality —50, 
      sourceType: Camera.PictureSourceType.PHOTOLIBRARY, 
      correctOrientation:true, 
      destinationType—Camera.DestinationType.DATA_URL 
    }; 

    navigator.camera.getPicture(function(imageURI){ 
      onSuccess (imageURI); 
    }, onFail, options); 
  }; 
}

android cordova

2022-09-30 14:47

1 Answers

I can't give you a definite solution because it doesn't contain the error content, but I think it's probably because I'm processing asynchronously where it should be processed synchronously, so I'm looking for a path to a photo that doesn't exist, and I'm forced to terminate it.

For example, for getPicture(), which should be handled by asynchronous processing:(var options values should also be used from the source code listed.)

navigator.camera.getPicture(options).then(function(imageURI){ 
  onSuccess (imageURI); 
}, function(error){
  onFail();
}); 


2022-09-30 14:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.