1

我知道这个问题可能已经在这里了,但我没有找到任何可以帮助我的东西。我想拍张照片并保存它的路径。我已经在拍照,但我无法在 Toast 中显示路径或将其保存在数据库中。

private static final int TAKE_PICTURE = 1;
private Uri outputFileUri;
SQLiteDatabase mydb;
static Uri capturedImageUri = null;
ImageView ecran;
Button b2,vertudo;
private String path;
ArrayList data;
ListView lista;

public void onClick(View v) {
            try{
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File file = new File(Environment.getExternalStorageDirectory(),"test.jpg");
            outputFileUri = Uri.fromFile(file);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, TAKE_PICTURE);
            }catch(Exception e){

            }

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    try{
        if (resultCode == RESULT_OK) {
            if (requestCode == TAKE_PICTURE) {
                outputFileUri = data.getData();
                path = getPath(outputFileUri);
                mydb.execSQL("INSERT INTO caminho(nome) VALUES('"+path+"');");
                Toast.makeText(getApplicationContext(), "Sucesso " + path,Toast.LENGTH_LONG).show();
            }
        }
    }catch(Exception e){
        Toast.makeText(getApplicationContext(),"Nao",Toast.LENGTH_LONG).show();
    }

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor =getContentResolver().query(uri, projection, null,null,null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
4

1 回答 1

0

您在 path = getPath(outputFileUri);中尝试执行的操作

我认为onActivityResult中的data.getData()将直接返回捕获图像的路径。

于 2014-04-30T12:53:49.097 回答