当我尝试(我认为)在我的物理设备的外部存储器(nexus 5 android 6.0)中创建一个文件时,我有一个权限异常,而它与4.3模拟设备一起工作正常。 我的权限很好,但是我收到了这个错误:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.media.action.VIDEO_CAPTURE flg=0x3 cmp=com.google.android.GoogleCamera/com.android.camera.VideoCamera clip={text/uri-list U:file:///storage/emulated/0/Pictures/MyCameraApp/VID_20151216_145322.mp4} (has extras) } from ProcessRecord{5dab894 22712:com.***} (pid=22712, uid=10199) with revoked permission android.permission.CAMERA
任何想法?
我将添加更多信息:
我的媒体工具是谷歌视频教程的基本复制/粘贴:
public class MediaUtils {
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
/** Create a file Uri for saving an image or video */
public static Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
/** Create a File for saving an image or video */
public static File getOutputMediaFile(int type){
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "MyCameraApp");
// This location works best if you want the created images to be shared
// between applications and persist after your app has been uninstalled.
// Create the storage directory if it does not exist
if (! mediaStorageDir.exists()){
if (! mediaStorageDir.mkdirs()){
Log.d("MyCameraApp", "failed to create directory");
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE){
mediaFile = new File(mediaStorageDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".jpg");
} else if(type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File
.separator +
"VID_"+ timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
}
我的意图:
Uri fileUri = MediaUtils.getOutputMediaFileUri(MediaUtils.MEDIA_TYPE_VIDEO);
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);
答案 0 :(得分:2)
API 23及更高版本上有一个新的权限系统。 在运行时请求许可。
您应该阅读此How to manage permission on Android 6.0和此Android request permission