How to select (select) multiple images using the camera’s API at the same time in the telephone power supply?

How to select or select multiple images at a time in phonegap camera APIuse I can only select one image at a time. I can select multiple files (including txt, pdf ..) in sdcard using this . So I want the same as for images. Camera.DestinationType.FILE_URI.

navigator.camera.getPicture(function(imageData) {
window.resolveLocalFileSystemURI(imageData, function(fileEntry) {
            fileEntry.file(function(fileObj) {
                    }, onFail, {
    quality : 50,
    destinationType : Camera.DestinationType.FILE_URI
});

My cordova is version 3.3, jQuery Mobile 1.3.2.

Please offer any plugins for this.

+4
source share
3 answers

. .

plugin and copy paste the java classes. permission. res folder res.

assets/www imagepicker.js imagepicker.js

index.html :

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="imagepicker.js"></script>

<script type="text/javascript">

    document.addEventListener("deviceready",onDeviceReady,false);

    function onDeviceReady(){

        window.imagePicker.getPictures(
                function(results) {
                    for (var i = 0; i < results.length; i++) {
                        alert('Image URI: ' + results[i]);

// read file type and size and file name like below(in comment)

/* window.resolveLocalFileSystemURI(results[i], function(fileEntry){
        fileEntry.file(function(fileObj) { 
            alert(fileEntry.name);
            alert(fileObj.size);
            alert(fileObj.type);
        }); 

    }, function (error) {
            alert('Error: ' + error);
        });*/
                    }
                }, function (error) {
                    alert('Error: ' + error);
                }
            );

    }
    </script>

Note: This should work only cordova 3.0 and above and android 4.0 and above

+2

var x=0;
function onPhotoDataSuccess(imageURI)
{
    x++;
    // Uncomment to view the base64-encoded image data
    console.log(imageURI);
	alert(imageURI);
    // Get image handle
    //
    var y = 'smallImage'+x;
    var smallImage = document.getElementById(y);
    alert(smallImage);
	smallImage.src = "data:image/jpeg;base64," + imageURI;
    // Unhide image elements
    //
    smallImage.style.display = 'block';
  
    // Show the captured photo
    // The in-line CSS rules are used to resize the image
    //
    //var fso=new ActiveXObject("Scripting.FileSystemObject");
    //fso.CopyFile("data:image/jpeg;base64," + imageURI,"file:///storage/sdcard/DCIM/");
      
    alert(smallImage.src)
}

x - ,

0

Open CameraLauncher.java file and replace these lines

String resizePath = getTempDirectoryPath() + "/resize.jpg";
this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis());

at

String resizePath = getTempDirectoryPath() + "/resize"+System.currentTimeMillis()+".jpg";
this.callbackContext.success("file://" + resizePath);
0
source

Source: https://habr.com/ru/post/1542116/


All Articles