开发者

Android get URI string from a called CameraView's picture

start camera intent:

void openCamera() {

   File imageDirectory = new File("/sdcard/myprog");
   if (!imageDirectory.isDirectory()) imageDirectory.mkdir();

   String path = imageDirectory.toString(开发者_如何学运维).toLowerCase();
   String name = imageDirectory.getName().toLowerCase();

  ContentValues values = new ContentValues(); 
  values.put(Media.TITLE, "Image"); 
  values.put(Images.Media.BUCKET_ID, path.hashCode());
  values.put(Images.Media.BUCKET_DISPLAY_NAME,name);

  values.put(Images.Media.MIME_TYPE, "image/jpeg");
  values.put(Media.DESCRIPTION, "Image capture by camera");
  values.put("_data", "/sdcard/myprog/1111.jpg");
    Uri uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
  Intent i = new Intent("android.media.action.IMAGE_CAPTURE"); 

  i.putExtra(MediaStore.EXTRA_OUTPUT, uri);

  startActivityForResult(i, 0); 

}

and then...

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

     if (requestCode==0 && resultCode==RESULT_OK)    {

         Uri path = data.getData();
...

I tried many sample to take a picture with my camera on my program, and then use that picture with my program, but:

-i get an exception here: Uri path = data.getData();

-or i get a null value to: Uri path = data.getData();

what is the correct way, to get the shoted camera picture url?

Thanks, Leslie


you need to do

Uri path = Uri.parse(imageDirectory.toString());

at least if imageDirectory is holding a string representation of a Uri

or i suppose you could just do this

Uri imagePath = Uri.parse(path);

since you are already getting the imagedirectory string

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜