首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

onActivityResult 中取参数值

2012-04-05 
onActivityResult 中取参数值,在线等android程序中,写了个拍照方法如下public void ImageCapture() {File

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();
}

热点排行