How can I do to get the path of the image I just uploaded and then save to the database with the path? I get the image from the Gallery, then with that image I wanted to take the path and save it to the SQLite database. I'm half-hearted on the subject: (
ImageButton contactImgView;
private String imagePath;
public void tela_cuidador_cadastrar_tema(){
setContentView(R.layout.tela_cuidador_cadastrar_tema);
contactImgView = (ImageButton) findViewById(R.id.imageButton1);
//Procura Imagem da galeria
contactImgView.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Contact Image"), 1);
}
});
}
@Override
public void onActivityResult(int reqCode, int resCode, Intent data) {
super.onActivityResult(reqCode, resCode, data);
if(resCode == RESULT_OK) {
if (reqCode == 1)
contactImgView.setImageURI(data.getData());
Uri imageUri = data.getData();
imagePath = getImagePath(imageUri);
Toast.makeText(MainActivity.this, imagePath, Toast.LENGTH_LONG).show();
}
}
public String getImagePath(Uri contentUri) {
String[] campos = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(contentUri, campos, null, null, null);
cursor.moveToFirst();
String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
cursor.close();
return path;
}
Only the message that was to be displayed appears blank and not the path: S.