简体   繁体   English

拍照并保存路径

[英]Take photo and save path

I know that probably this question is already here but i didnt find anything that could help me. 我知道这个问题可能已经存在,但是我没有找到任何可以帮助我的问题。 I wanted to take a photo and save its path. 我想拍照并保存其路径。 I'm already taking the photo but i cant show the path in the Toast or save it in the database. 我已经在拍照,但是无法在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);
}

What you are trying to do in path = getPath(outputFileUri); 您试图在path = getPath(outputFileUri);中执行的操作

I think data.getData() in onActivityResult wil directly returns the path of the captured image. 我认为onActivityResult中的 data.getData()将直接返回捕获图像的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM