Reputation: 47
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.
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);
}
Upvotes: 1
Views: 144
Reputation: 61
What you are trying to do in path = getPath(outputFileUri);
I think data.getData() in onActivityResult wil directly returns the path of the captured image.
Upvotes: 0