从相机意图ACTION_IMAGE_CAPTURE获取路径

时间:2010-11-15 13:27:19

标签: android-widget

您好我正在使用相机意图如下......

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, (new File(Environment.getExternalStorageDirectory(),String.valueOf(System.currentTimeMillis()) + ".jpg")));
startActivityForResult(cameraIntent, 0);

现在我不知道如何在onActivityResult()方法中获取当前点击的图像路径请相信如果有人知道帮帮我...

1 个答案:

答案 0 :(得分:0)

我的解决方案:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CANCELED) 
    {
        Toast toast = Toast.makeText(this,"camera cancelled", 10000);
        toast.show();
        return;
    }
    if ((requestCode == CustomerRequestActivity.TAKE_IMAGE) && (resultCode == RESULT_OK))
    {
        // mode = MODE_VIEWER;
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(mCapturedImageURI, projection, null,null, null);
        int column_index_data = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();

        //THIS IS WHAT YOU WANT!
        String capturedImageFilePath = cursor.getString(column_index_data);
        Bitmap bm;
        Log.v("/////////////", "///////");
        Log.v("\n\n\n\n", capturedImageFilePath);
        Log.v("///////////", "///////////");
        bm = BitmapFactory.decodeFile(capturedImageFilePath);
        capturedImageView.setImageBitmap(bm);
    }
}