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     }

 

posted @ 2016-07-19 18:06  夏落若的博客  阅读(21105)  评论(0编辑  收藏  举报