如何在不活动android上使用onRequestPermissionsResult?

时间:2017-11-09 05:27:41

标签: android

我的设备棉花糖,所以我应该添加获取权限代码。 我的app相机预览应用。 获得权限代码,而不是活动。

所以,我不知道如何在非活动

上使用onRequestPermissionsResult

我的来源

public class WebClient {
     public void readyCamera() {
         // camera releation work.
     }

     private void setCamera() {
          Activity activity = MainActivity.getMainActivity(); //get Activity

          if (Build.VERSION.SDK_INT >= M) { //over marshmallow
               if (ContextCompat.checkSelfPermission(activity , Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED) { //no permission
                     if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA)) {
                         ActivityCompat.requestPermissions(activity, new String[] {Manifest.permission.CAMERA}, 1000);
                     } else {
                          ActivityCompat.requeestPermissions(activity, new String[] {Manifest.permission.CAMERA}, 1000);
                     }
               } else {
                    readyCamera();
               }
            } readyCamera();
     }    

     @Override
     private void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
           switch (requestCode) {
               case 1000:
                    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                         readyCamera();
                    } else {
                    }
            }
      }

如何在非活动中使用onRequestPermissionsResult方法?

感谢:)

0 个答案:

没有答案