android 7.0相机权限,fix:android 7.0 相机权限问题FILEPROVIDER

/**

* 选择相机

*/

private void showCameraAction()

{

// 跳转到系统照相机

int currentapiVersion = android.os.Build.VERSION.SDK_INT;

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

if (cameraIntent.resolveActivity(getActivity().getPackageManager()) != null) {

// 设置系统相机拍照后的输出路径

// 创建临时文件

try {

mTmpFile = FileUtils.createTmpFile(getActivity());

} catch (IOException e) {

e.printStackTrace();

}

if (mTmpFile != null && mTmpFile.exists()) {

if (currentapiVersion < 24) {

// 从文件中创建uri

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTmpFile));

} else {

//兼容android7.0 使用共享文件的形式

ContentValues contentValues = new ContentValues(1);

contentValues.put(MediaStore.Images.Media.DATA, mTmpFile.getAbsolutePath());

Uri uri = getActivity().getApplication().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

}

startActivityForResult(cameraIntent, REQUEST_CAMERA);

} else {

Toast.makeText(getActivity(), "图片错误", Toast.LENGTH_SHORT).show();

}

} else {

Toast.makeText(getActivity(), R.string.msg_no_camera, Toast.LENGTH_SHORT).show();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值