&引用;媒体“U类型”图像无法解析为变量;在PictureCallback(android)中
我使用的代码来自 但我对这行的PictureCallback有个问题 File pictureFile=getOutputMediaFile(媒体类型图像) 问题是“媒体类型图像无法解析为变量”。如何解决此问题?您可以检查以下代码## 您还可以查看更多信息 您必须对清单文件中的外部存储使用权限&引用;媒体“U类型”图像无法解析为变量;在PictureCallback(android)中,android,Android,我使用的代码来自 但我对这行的PictureCallback有个问题 File pictureFile=getOutputMediaFile(媒体类型图像) 问题是“媒体类型图像无法解析为变量”。如何解决此问题?您可以检查以下代码## 您还可以查看更多信息 您必须对清单文件中的外部存储使用权限 <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="an
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
您可以检查以下代码##
您还可以查看更多信息
您必须对清单文件中的外部存储使用权限
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
如果《android指南》中的摄像头示例引导您来到这里,请阅读以下内容 他们在文档底部声明了方法,
也让我偏离了正轨,希望它能帮助你如果《android指南》中的摄像头示例引导你来到这里,那么请阅读本文 他们在文档底部声明了方法, 也让我偏离了轨道,希望它能帮助您getOutputMediaFile() 此方法由开发人员站点创建,用于保存捕获的图像 要使其运行,请完成您的代码 将此函数粘贴到活动中
/** Create a file Uri for saving an image or video */
private static Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
/** Create a File for saving an image or video */
private 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), "MTN_Camera");
// 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()){
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 {
return null;
}
return mediaFile;
}
getOutputMediaFile()
此方法由开发人员站点创建,用于保存捕获的图像
要使其运行,请完成您的代码
将此函数粘贴到活动中
/** Create a file Uri for saving an image or video */
private static Uri getOutputMediaFileUri(int type){
return Uri.fromFile(getOutputMediaFile(type));
}
/** Create a File for saving an image or video */
private 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), "MTN_Camera");
// 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()){
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 {
return null;
}
return mediaFile;
}
是否可以复制和粘贴实际错误消息或任何相关的logcat输出?是否可以复制和粘贴实际错误消息或任何相关的logcat输出?