Phonegap(3.0.0) Camera not successful on first try

前端 未结 6 2344
温柔的废话
温柔的废话 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条回答
  •  萌比男神i
    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);
                }
        }
    
        //...
    }
    

提交回复
热议问题