我希望使用设备相机显示图像捕获,并且我已使用下面的代码。但是我在onActivityResult中返回的数据中获得空值。所以请为我提供解决方案..
感谢,
我的代码是:
File root = new File(Environment.getExternalStorageDirectory()+"/TestCameraGallery");
root.mkdirs();
MyCameraGallery = new File(root, "mycamerapicname");
Uri outputFileUri = Uri.fromFile(MyCameraGallery );
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAMERA_PIC_REQUEST)
{
Uri uri = data.getData();
}
}
uri的值为null并给出空指针异常所以请帮助我
答案 0 :(得分:2)
使用您的代码,您将获得低分辨率图像。如果您想获得高分辨率图像,可以参考this answer.
您也可以参考this blog
答案 1 :(得分:0)
最终得到解决方案
String imageName = "image.jpg" ;
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, imageName);
uri_captureImage = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri_captureImage);
startActivityForResult(intent, requestCode_camera);
String imageName = "image.jpg" ;
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, imageName);
uri_captureImage = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri_captureImage);
startActivityForResult(intent, requestCode_camera);
和onAcitivity为结果
String[] projection = new String[] {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(uri_captureImage, projection, null, null, null);
cursor.moveToFirst();
String capimage_path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));