Phonegap(3.0.0) Camera not successful on first try

前端 未结 6 2150
温柔的废话
温柔的废话 2021-02-15 17:21

For testing purposes I copied the full example found on the phonegap camera API and I put an alert on onPhotoDataSuccess to test when the function is fired. On the

相关标签:
6条回答
  • 2021-02-15 17:32

    had exactly the same problem. Capture success was only receiving the callback after captureVideo had been called for the second time.

    Just replaced my old app/bin/cordova.jar file with new 3.2.0 cordova-dev.jar (in eclispe) and all back in order :)

    0 讨论(0)
  • 2021-02-15 17:34

    I had this problem with Cordova 3.7.1 and Camera 0.3.5 - every time I called the plugin, it did not return the image/path and on second call it returned error "Canceled" for the previous call.

    The problem was that my main activity had own onActivityResult which did not correctly call the super's method.

    public class MainActivity extends CordovaActivity {
        //...
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
                if (requestCode == MyCustomActivity) {
                        doMyCustomActivity(requestCode);
                }
        }
    
        //...
    }
    

    To fix it, I had to add ELSE to call the correct handler:

    public class MainActivity extends CordovaActivity {
        //...
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
                if (requestCode == MyCustomActivity) {
                        doMyCustomActivity(requestCode);
                }
                else { //this was missing - call other Activity of plugins
                    super.onActivityResult(requestCode, resultCode, intent);
                }
        }
    
        //...
    }
    
    0 讨论(0)
  • 2021-02-15 17:42

    I don't know whether this is right solution or not but its work for me perfectly. It would be batter to trace your log cat and found exact issue.

    Try to use navigator.camera.PictureSourceType instated of pictureSource. so it looks like

    <button onclick="getPhoto(navigator.camera.PictureSourceType.PHOTOLIBRARY);">From Photo Library</button><br>
    

    and same way replace in Javascript code as well

    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI });
    

    OR

    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: navigator.camera.DestinationType.DATA_URI });
    

    Update: Try to save your corodova.js locally and call from local dir, so your dir should like

    assets/www/js/cordova.js

    <script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>
    

    Working Code

    Hope this will help you !!!

    0 讨论(0)
  • 2021-02-15 17:48

    I had the same problem after updating from 3.0.0 to 3.1.0. Delayed camera, no geolocation, etc.

    Look if the file platforms\android\cordova\version states an old version. Then you need to update your platform. So here is what i did.

    • Remove all plugins: cordova plugin rm org.apache.cordova.camera
    • Remove the platform: cordova platform remove android (will delete changes you have made to *.java files)
    • Add the platform: cordova platform add android
    • Add all plugins: cordova plugin add org.apache.cordova.camera
    • Check permissions
    • Build it

    It's basically like creating a new project.

    0 讨论(0)
  • 2021-02-15 17:53

    I had this exact problem on Cordova 3.4.0, with a fresh Cordova install (no upgrade from previous version as some others posted). Taking the first picture would do nothing- no success callback, no fail callback. Taking the second picture would result in a success callback but the DATA_URL data (the base64 encoded image) that came back was the data from the FIRST picture.

    For me it was working fine on one phone, various emulators, etc. except on one Android 4.2 phone where it did this. The solution was to uninstall the app from the phone using the phone's application management under settings, then reinstall the app- then the first picture would trigger the success callback with its own data.

    No idea why, but uninstalling and reinstalling the app resolved it for me.

    0 讨论(0)
  • 2021-02-15 17:54

    I met the same problem and solved it. Because you import two "cordova.js" in your app, and maybe one is in the iframe. you can use "parent.cordova" in iframe instead.

    0 讨论(0)
提交回复
热议问题