2016-04-27 6 views
1

Ich verwende Bibliothek von Google, um Berechtigungen auf Android 6 zu behandeln. Das erste Mal, wenn ich auf die Schaltfläche klicke, um Bilder zu erfassen, werden die Berechtigungen CAMERA und WRITE_EXTERNAL_STORAGE eingegeben .Fehler beim Ausgeben des Ergebnisses - Nicht-void-Methode kann nicht ausgeführt werden openCamera

Nachdem ich beide Berechtigungen App stürzt ab mit der Fehlermeldung angenommen haben, können Sie unten sehen:

E/AndroidRuntime: FATAL EXCEPTION: main 
        Process: com.example.debug, PID: 22768 
        java.lang.RuntimeException: Failure delivering result ResultInfo{[email protected]:requestPermissions:, request=123, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example.debug/com.example.camera.CameraActivity}: java.lang.RuntimeException: Cannot execute non-void method openCamera 
         at android.app.ActivityThread.deliverResults(ActivityThread.java:3699) 
         at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742) 
         at android.app.ActivityThread.-wrap16(ActivityThread.java) 
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393) 
         at android.os.Handler.dispatchMessage(Handler.java:102) 
         at android.os.Looper.loop(Looper.java:148) 
         at android.app.ActivityThread.main(ActivityThread.java:5417) 
         at java.lang.reflect.Method.invoke(Native Method) 
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
        Caused by: java.lang.RuntimeException: Cannot execute non-void method openCamera 
         at pub.devrel.easypermissions.EasyPermissions.runAnnotatedMethods(EasyPermissions.java:229) 
         at pub.devrel.easypermissions.EasyPermissions.onRequestPermissionsResult(EasyPermissions.java:186) 
         at com.example.camera.CameraActivity.onRequestPermissionsResult(CameraActivity.java:243) 
         at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:6553) 
         at android.app.Activity.dispatchActivityResult(Activity.java:6432) 
         at android.app.ActivityThread.deliverResults(ActivityThread.java:3695) 
         at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)  
         at android.app.ActivityThread.-wrap16(ActivityThread.java)  
         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)  
         at android.os.Handler.dispatchMessage(Handler.java:102)  
         at android.os.Looper.loop(Looper.java:148)  
         at android.app.ActivityThread.main(ActivityThread.java:5417)  
         at java.lang.reflect.Method.invoke(Native Method)  
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  

und die openCamera() Methode:

@Override 
@AfterPermissionGranted(RC_CAMERA_PERM) 
public void openCamera(int option) { 
    if (EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { 
     // Have permission, do the thing! 
     Log.i(TAG, "openCamera Has Permissions "); 

     Intent intent; 

     switch (option) { 
      case RECORD_VIDEO : 
       intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
       intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, FIVE_MINS_IN_SECS); 
       startActivityForResult(intent, RECORD_VIDEO); 
       break; 
      case CAPTURE_IMAGE : 
       ContentValues values = new ContentValues(); 
       values.put(MediaStore.Images.Media.TITLE, "Image File name"); 
       mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 

       intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
       intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI); 
       startActivityForResult(intent, CAPTURE_IMAGE); 
       break; 
      default: 
       Log.i(TAG, "openCamera wrong option "); 
       break; 
     } 

    } else { 
     // Ask for Camera permission 
     EasyPermissions.requestPermissions(this, getString(R.string.ask_camera_permission), 
       RC_CAMERA_PERM, Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE); 
    } 
} 

Antwort

6

Sie diese Ausnahme erhalten, weil EasyPermission nicht aufrufen Ihre Methode openCamera, da es den Parameter option hat. Die mit AfterPermissionGranted annotierten Methoden müssen ungültig sein, damit EasyPermission sie aufrufen kann.

// Method must be void so that we can invoke it 
if (method.getParameterTypes().length > 0) { 
    throw new RuntimeException("Cannot execute non-void method " + method.getName()); 
} 

Um das Problem zu beheben, müssen Sie entfernen Sie alle Parameter aus dem Verfahren openCamera:

Dieser Zustand ist in der Quelle EasyPermission ausdrücklich bestätigt.