当前位置: 代码迷 >> Android >> onActivityResult 中取参数值
  详细解决方案

onActivityResult 中取参数值

热度:43   发布时间:2016-05-01 21:42:22.0
onActivityResult 中取参数值,在线等
android程序中,写了个拍照方法如下
 public void ImageCapture() {
File DatalDir = Environment.getExternalStorageDirectory();
File myDir = new File(DatalDir, "/DCIM/Camera");
myDir.mkdirs();
String mDirectoryname = DatalDir.toString() + "/DCIM/Camera";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hhmmss",
Locale.SIMPLIFIED_CHINESE);
File tempfile = new File(mDirectoryname, sdf.format(new Date())
+ ".jpg");//tempfile为图片的路径
if (tempfile.isFile())
tempfile.delete();
Uri Imagefile = Uri.fromFile(tempfile);
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Imagefile);
cameraIntent.putExtra(imgurl, tempfile);
startActivityForResult(cameraIntent, REQ_CODE_CAMERA);
}
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {  
  super.onActivityResult(requestCode, resultCode, data);  
  if (resultCode == RESULT_OK)
  {  
 
  if(requestCode==REQ_CODE_CAMERA)
  { 
  //此处如何得到刚那图片的路径
  }
  }  
  }  
现问:在 onActivityResult 方法中,如何得到刚那图片的路径
  thanks

------解决方案--------------------
File tempfile; //全局变量
tempfile = new File(mDirectoryname, sdf.format(new Date())
+ ".jpg");//tempfile为图片的路径

if(requestCode==REQ_CODE_CAMERA)
{
//此处如何得到刚那图片的路径
String str = tempfile.getPath();
}