if(! (pm.checkPermission("android.permission.CAMERA", "com.zxc.criminalintent")==PackageManager.PERMISSION_GRANTED ) )
{
Intent i = new Intent(getActivity(), CrimeCameraActivity.class);
CrimeFragment.this.startActivityForResult(i, CrimeFragment.this.REQUEST_PHOTO);
}
else
{
Toast.makeText(CrimeFragment.this.getActivity(),
"请在设置中打开相机权限", Toast.LENGTH_SHORT)
.show();
}
@TargetApi(9)
@Override
public void onResume() {
super.onResume();
Log.i(TAG, "camera fragment resuming " );
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
try {
mCamera = Camera.open(0);
} catch (Exception exception) {
Log.e(TAG, "Error setting up preview display", exception);
if (mCamera!=null)
{
mCamera.release();
}
AlertDialog.Builder builder = new AlertDialog.Builder(CrimeCameraFragment.this.getActivity());
builder.setTitle("提示");
builder.setMessage("请检查相机权限设置");
builder.setCancelable(false);
builder.setPositiveButton("确定",new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
CrimeCameraFragment.this.getActivity().finish();
}
});
builder.create().show();
return ;
}
// try{
//
// mCamera = Camera.open(Camera.getNumberOfCameras()-1);
// // Camera.Parameters parameter = mCamera.getParameters();
// // mCamera.setParameters(parameter);
// }
// catch(RuntimeException e){
//
// //System.out.println("open()方法有问题");
//
// Toast.makeText(this.getActivity(),
// "请在设置中打开相机权限", Toast.LENGTH_SHORT)
// .show();
// }
//mCamera = Camera.open(0);
} else {
try {
mCamera = Camera.open();
} catch (Exception exception) {
Log.e(TAG, "Error setting up preview display", exception);
if (mCamera!=null)
{
mCamera.release();
}
AlertDialog.Builder builder = new AlertDialog.Builder(CrimeCameraFragment.this.getActivity());
builder.setTitle("提示");
builder.setMessage("请检查相机权限设置");
builder.setCancelable(false);
builder.setPositiveButton("确定",new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
CrimeCameraFragment.this.getActivity().finish();
}
});
builder.create().show();
return ;
}
// try{
// mCamera = Camera.open();
// // Camera.Parameters parameter = mCamera.getParameters();
// // mCamera.setParameters(parameter);
// }
// catch(RuntimeException e){
//
// // System.out.println("open()方法有问题");
// Toast.makeText(this.getActivity(),
// "请在设置中打开相机权限", Toast.LENGTH_SHORT)
// .show();
// }
//mCamera = Camera.open();
}
}
Android6.0以下系统判断相机权限
这种方式目前也是一种折中的方法。
今天的文章 android 相机权限检查分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/78497.html