2017-11-29 16 views
-1

起動時にカメラを許可する許可を求めるアプリを設計しました。しかし、Androidの6のために、私はNullに戻っているcamera.setDisplayOrentaion(90);を設定しているAndroid起動時にAndroid 6以上でアプリがクラッシュする

allow the access to camera Camera.open() return null 

などのアプリがクラッシュした上で。

答えて

0

あなたがActivityonRequestPermissionsResultPERMISSION_GRANTEDとの間でカメラを初期化することは想定されていません。アプリでランタイム権限を適切に処理する方法の詳細については、thisを参照してください。

0

許可

int permissionCheck = ContextCompat.checkSelfPermission(thisActivity, 
     Manifest.permission.CAMERA); 

のための最初のチェックに許可が、許可されたpermission check = PackageManager.PERMISSION_GRANTEDまたはその逆PERMISSION_DENIEDされた場合。

あなたはそれを求めることができます。

if (ContextCompat.checkSelfPermission(thisActivity, 
       Manifest.permission.CAMERA) 
     != PackageManager.PERMISSION_GRANTED) { 

    // Should we show an explanation? 
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, 
      Manifest.permission.CAMERA)) { 

     // Show an explanation to the user *asynchronously* -- don't block 
     // this thread waiting for the user's response! After the user 
     // sees the explanation, try again to request the permission. 

    } else { 

     // No explanation needed, we can request the permission. 

     ActivityCompat.requestPermissions(thisActivity, 
       new String[]{Manifest.permission.CAMERA}, 
       MY_PERMISSIONS_REQUEST_CAMERA); 

     // MY_PERMISSIONS_REQUEST_CAMRA is an 
     // app-defined int constant. The callback method gets the 
     // result of the request. 
    } 
} 

あなたは応答を処理する必要があります。

@Override 
public void onRequestPermissionsResult(int requestCode, 
     String permissions[], int[] grantResults) { 
    switch (requestCode) { 
     case MY_PERMISSIONS_REQUEST_CAMERA: { 
      // If request is cancelled, the result arrays are empty. 
      if (grantResults.length > 0 
       && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

       // permission was granted, yay! Open 
       // camera, take photo. 

      } else { 

       // permission denied, boo! Disable the 
       // functionality that depends on this permission. 
      } 
      return; 
     } 

     // other 'case' lines to check for other 
     // permissions this app might request 
    } 
} 
関連する問題