1. 程式人生 > >android 6 權限檢查 zxing

android 6 權限檢查 zxing

ssi ont [] details des manage err 開啟 ack

/*// 新增
    private static final int MY_PERMISSIONS_REQUEST_CALL_CAMERA = 1;//請求碼,自己定義

    // 新增Android6.0 權限檢查
    @Override
    protected void onStart() {
        super.onStart();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                // 如果沒有授權,則請求授權
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, MY_PERMISSIONS_REQUEST_CALL_CAMERA);
            } else {
                // 有授權,直接開啟攝像頭
            }
        }
    }
    // 新增Android6.0 權限檢查
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        // 判斷請求碼
        if (requestCode == MY_PERMISSIONS_REQUEST_CALL_CAMERA) {
            //grantResults授權結果
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // 成功,開啟攝像頭
                // callCamera();
            } else {
                // 授權失敗
                Toast.makeText(CaptureActivity.this, "Permission Denied", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.parse("package:" + CaptureActivity.this.getPackageName()));
                CaptureActivity.this.startActivityForResult(intent, 1028);
                this.finish();
            }
            return;
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    // 新增
*/

android 6 權限檢查 zxing