Android 6.0系统动态请求系统相机和读取手机存储权限
Posted 志向远大
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android 6.0系统动态请求系统相机和读取手机存储权限相关的知识,希望对你有一定的参考价值。
一、请求系统相机权限1 private static final int TAKE_PHOTO_REQUEST_CODE = 1; 2 3 public static String takePhoto(Context context, int requestCode) 4 String filePath = ""; 5 if (ContextCompat.checkSelfPermission(context, 6 Manifest.permission.CAMERA) 7 != PackageManager.PERMISSION_GRANTED) 8 ActivityCompat.requestPermissions((Activity) context, 9 new String[]Manifest.permission.CAMERA, 10 TAKE_PHOTO_REQUEST_CODE); 11 else 12 Intent intent = new Intent( 13 MediaStore.ACTION_IMAGE_CAPTURE, null); 14 filePath = AppApplication.getInstance().getCachePath() + File.separator + MD5.md5(String.valueOf(System.currentTimeMillis())) + "camera" + ".png"; 15 intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri 16 .fromFile(new File(filePath))); 17 ((Activity) context).startActivityForResult(intent, requestCode); 18 19 20 return filePath; 21
二、获取相册照片要申请的权限
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ActivityCompat.requestPermissions((Activity) mContext, new String[] Manifest.permission.READ_EXTERNAL_STORAGE , SELECT_PHOTO_REQUEST_CODE); else // 从相册中选择图片 Intent intent2 = new Intent( Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); // CHOSE_PIC设置标识 ((Activity) mContext).startActivityForResult(intent2, CHOSE_PIC);
以上是关于Android 6.0系统动态请求系统相机和读取手机存储权限的主要内容,如果未能解决你的问题,请参考以下文章