From my application I access the gallery to select an image, after selecting it in the database I keep the path of that image, but then to load it in an imageview it does not load it with the saved route and it is that I notice the next problem, the path that I saved is not the one that says it has the file really.
public class Agregar_foto extends AppCompatActivity{
ImageView imagen;
Uri path;
String numero;
BDHelper mDbHelper;
Button guardar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.foto);
imagen = (ImageView) findViewById(R.id.agfoto);
guardar = (Button) findViewById(R.id.btnguardarfoto);
Bundle mibundle;
mibundle = this.getIntent().getExtras();
numero = mibundle.getString("numero_telefonito");
mDbHelper = new BDHelper(this,"bd_vinculator",null,1);
}
public void irafoto(View v){
Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/");
startActivityForResult(intent.createChooser(intent,"Seleccione la aplicación"),10);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
path = data.getData();
Toast.makeText(this,path.toString(),Toast.LENGTH_LONG).show();
imagen.setImageURI(path);
}
}
public void guardarFoto(View v){
try{
SQLiteDatabase db = mDbHelper.getWritableDatabase();
if (path.toString().isEmpty()) {
}else{
String sql = "Update CONTACTO set " + Utilidades.Campo_foto + " = ' " + path.toString() +"'" ;
try{
db.execSQL(sql);
db.close();
}catch(Exception e){
finish();
}
}
}catch(Exception e){
finish();
}
finish();
}
@Override
public void onResume(){
super.onResume();
buscar();
}
private void buscar() {
SQLiteDatabase db = mDbHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT foto FROM " + Utilidades.Tabla_Contacto + " WHERE " + Utilidades.Campo_telef + " = '"+numero + "'",null);
cursor.moveToFirst();
Toast.makeText(this,cursor.getString(0),Toast.LENGTH_LONG).show();
try{
imagen.setImageURI(Uri.parse(cursor.getString(0)));
}catch(Exception e){
Toast.makeText(this,e+"",Toast.LENGTH_LONG).show();
}
db.close();
}
}
The path that I keep in the database (local sqlite) is like this: content: // media / external / images / media / 39 And the route that tells me inside the cell phone is: /storage/emulated/0/Pictures/Screenshots/454980.png If I put in the image.setImageUri the second route loads the image without problems, but if I put the first one it does not, how could I get the second path in code?.