码迷,mamicode.com
首页 > 移动开发 > 详细

Android 6.0系统动态请求系统相机权限

时间:2016-07-19 18:50:44      阅读:726      评论:0      收藏: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     }

 

Android 6.0系统动态请求系统相机权限

标签:

原文地址:http://www.cnblogs.com/zimengfang/p/5685755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!