Currently in my Android application, I have in my menu the possibility of saving an image, for this I have a form where I ask the user to choose one of your phone with the following code
Code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if(resultCode == RESULT_OK && requestCode == PICK_IMAGE){
// imageUri = data.getData();
//foto_gallery.setImageURI(imageUri);
//foto_gallery.setBackground(null);
imageUri = data.getData();
foto_gallery.setImageURI(imageUri);
foto_gallery.setBackground(null);
foto_gallery.buildDrawingCache();
Bitmap bmap = foto_gallery.getDrawingCache();
//creamos el drawable redondeado
RoundedBitmapDrawable roundedDrawable =
RoundedBitmapDrawableFactory.create(getResources(), bmap);
//asignamos el CornerRadius
roundedDrawable.setCornerRadius(bmap.getHeight());
roundedDrawable.setCircular(true);
ImageView imageView = (ImageView) findViewById(R.id.foto_gallery);
imageView.setImageDrawable(roundedDrawable);
DbHelper db = new DbHelper(this);
if (db != null) {
ContentValues value = new ContentValues();
value.put("IMAGENURL", imageUri.toString());
db.saveImagen(value);
}
What this does is choose the image, make an "Attempt to leave it round" and proceed to save it in sqlLITe, until here all right, it shows the image correctly in the menu etc, what I keep in SQL LITE is the URI of the imgen in this case that newly probe saves
content://media/external/images/media/15525
Now when I close the application and I open it again, I call to recover image and sufactly brings me the same uri
content://media/external/images/media/15525
but when it comes to seeing the image it comes empty, I would like to know because it could be that the image does not appear if it previously appears, and is the same uri,
This is the code in the master where you call when you retrieve and set the image
public void MenuConfiguracion() {
Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar_toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.bringToFront();
drawer.requestLayout();
final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.bringToFront();
navigationView.requestLayout();
ImageView profile = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.foto_gallery);
String auxruta = this.cargarFotoPerfil();
Uri myUri = Uri.parse(auxruta);
profile.setImageURI(myUri);
}
public String cargarFotoPerfil(){
String auxUri= "";
DbHelper db = new DbHelper(this);
if (db != null) {
Cursor auxCursor = db.recuperarImagen();
auxCursor.moveToFirst();
while (!auxCursor.isAfterLast()) {
if(auxCursor.getString(auxCursor.getColumnIndex("IMAGENURL"))!=null){
auxUri = auxCursor.getString(auxCursor.getColumnIndex("IMAGENURL"));
}
auxCursor.moveToNext();
}
}
return auxUri;
}
this is the logCAT
** Unable to open content: content://media/external/images/media/15525
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/15525 from pid=14438, uid=10188 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1620)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:692)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1155)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:991)
at android.content.ContentResolver.openInputStream(ContentResolver.java:711)
at android.widget.ImageView.resolveUri(ImageView.java:853)
at android.widget.ImageView.setImageURI(ImageView.java:465)
at banred.twoinnovateit.com.bimo.Menu_Master.MenuConfiguracion(Menu_Master.java:112)
at banred.twoinnovateit.com.bimo.Menu_Master.onCreate(Menu_Master.java:40)
at banred.twoinnovateit.com.bimo.Home.onCreate(Home.java:29)
at android.app.Activity.performCreate(Activity.java:6877)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3209)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3352)
at android.app.ActivityThread.access$1100(ActivityThread.java:223)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1797)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)**