Android eNONT(无此类文件或目录)
一切正常uri正在拍摄图像和路径,但当在second Acitivity中返回时,图像不会显示在imageView中,并在logcat中显示,请帮助 E/ashish:/storage/simulated/0/Pictures/FotoAula/IMG_20180329_183302.jpg E/BitmapFactory:无法解码流:java.io.FileNotFoundException:/storage/emulated/0/Pictures/FotoAula/IMG\u 20180329\u 183302.jpg:打开失败:eNote(没有这样的文件或目录) 梅尼费斯特 ** 这是第二项活动 您正在再次调用Android eNONT(无此类文件或目录),android,Android,一切正常uri正在拍摄图像和路径,但当在second Acitivity中返回时,图像不会显示在imageView中,并在logcat中显示,请帮助 E/ashish:/storage/simulated/0/Pictures/FotoAula/IMG_20180329_183302.jpg E/BitmapFactory:无法解码流:java.io.FileNotFoundException:/storage/emulated/0/Pictures/FotoAula/IMG\u 2018032
getOutputMediaFile()
。你以后再做。所以你得到了一个不同的文件名。里面有不同的日期和时间
该文件不存在
您应该记住并使用第一次调用getOutputMediaFile()
时得到的路径
与相机配合使用的那个
您正在再次调用getOutputMediaFile()
。你以后再做。所以你得到了一个不同的文件名。里面有不同的日期和时间
该文件不存在
您应该记住并使用第一次调用getOutputMediaFile()
时得到的路径
用于照相/摄像机的那一个。您是否已授予所需的读写存储权限?是的,我更新了我的问题,看到我已授予了所有权限permissions@Rahulrr2602好啊您的设备运行的是哪个Android版本?另外,请告诉我你的目标版本是什么。代码的哪一部分给了您这个错误?在每个出现这个错误的版本中,您是否给了所需的读写存储权限?是的,我更新了我的问题,看到我给了所有permissions@Rahulrr2602好啊您的设备运行的是哪个Android版本?另外,请告诉我你的目标版本是什么。代码的哪一部分给了你这个错误?在每个版本中都有这个错误调用什么?什么是“onActivity”?我在onActivityResult中再次调用了该方法,所以我要求我是否再次调用..我应该做什么为我编写
我要求我是否再次调用..
???奇怪的问题!我不是说过你不应该吗?打什么电话?什么是“onActivity”?我在onActivityResult中再次调用了该方法,所以我要求我是否再次调用..我应该做什么为我编写我要求我是否再次调用..
???奇怪的问题!我不是说过你不应该吗?
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />**
camera = (ImageView) findViewById(R.id.takePic);
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
file = Uri.fromFile(getOutputMediaFile());
i.putExtra(MediaStore.EXTRA_OUTPUT, file);
startActivityForResult(i, CAMERA_REQUEST_CODE);
// Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// startActivityForResult(intent, CAMERA_REQUEST_CODE);
}
});
private static File getOutputMediaFile()
{
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "FotoAula");
if (!mediaStorageDir.exists()){
if (!mediaStorageDir.mkdirs()){
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
return new File(mediaStorageDir.getPath() + File.separator +
"IMG_"+ timeStamp + ".jpg");
}
private String getPath(Uri uri) throws URISyntaxException {
final boolean needToCheckUri = Build.VERSION.SDK_INT >= 19;
String selection = null;
String[] selectionArgs = null;
// Uri is different in versions after KITKAT (Android 4.4), we need to
// deal with different Uris.
if (needToCheckUri && DocumentsContract.isDocumentUri(getApplicationContext(), uri)) {
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
return Environment.getExternalStorageDirectory() + "/" + split[1];
} else if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
uri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
} else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("image".equals(type)) {
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
selection = "_id=?";
selectionArgs = new String[]{
split[1]
};
}
}
if ("content".equalsIgnoreCase(uri.getScheme())) {
String[] projection = {
MediaStore.Images.Media.DATA
};
Cursor cursor = null;
try {
cursor = getContentResolver()
.query(uri, projection, selection, selectionArgs, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if (cursor.moveToFirst()) {
return cursor.getString(column_index);
}
} catch (Exception e) {
e.printStackTrace();
}
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}
return null;
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider.
*/
public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is DownloadsProvider.
*/
public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is MediaProvider.
*/
public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
File file = getOutputMediaFile();
String path = null;
try {
path = getPath(Uri.fromFile(getOutputMediaFile()));
} catch (URISyntaxException e) {
e.printStackTrace();
}
Intent intent = new Intent(this, PictureActivity.class);
intent.putExtra("imgUrl", path.toString());
startActivity(intent);
}
}
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
Log.e("ashish", bundle.getString("imgUrl") + "");
path = Uri.parse(bundle.getString("imgUrl"));
ImageView selfiiii = (ImageView) findViewById(R.id.mySelfie);
selfiiii.setImageURI(path);
}
path = getPath(Uri.fromFile(getOutputMediaFile()));