检索相机

时间:2016-02-07 03:06:43

标签: android android-intent

我正在尝试使用手机摄像头拍摄图像,但无法获取图像位置。

如何检索Uri?

Uri tempUri = null;
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "MyLibraryManager");
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_"+ timeStamp + ".jpg");
tempUri = Uri.fromFile(mediaFile);
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
cameraIntent.putExtra("crop", "true");
cameraIntent.putExtra("outputX", cropwidth);
cameraIntent.putExtra("outputY", cropheight);
getActivity().startActivityForResult(cameraIntent, CAMERA_IMAGE_CAPURE);

onActiviryResult:

if(resultCode == RESULT_OK && intent != null){
    Log.d("abd", "Intent: "+ intent);
    Log.d("abd", "location: "+ MediaStore.EXTRA_OUTPUT);
}

输出

  

abd:意图:意图{act = file:///storage/emulated/0/Pictures/MyLibraryManager/IMG_20160207_135753.jpg(有额外内容)}

     

abd:xyz:output

1 个答案:

答案 0 :(得分:2)

正如您在日志中看到的那样:

  

意图   {ACT =文件:///storage/emulated/0/Pictures/MyLibraryManager/IMG_20160207_135753.jpg   (有额外的)}

这是意图的行动。你可以这样说:

String filePath = intent.getAction();