1

I'm new to Android, sorry if my question doesn't make a lot of sense, but I've searched a lot and could't make this clear yet.

I have an Item object, that gets build with data pulled from an sqlite db. One of this Item's fields is a Bitmap (stored as a Uri in the DB) that should be created from the Uri in the Item's constructor.

I'm getting java.io.FileNotFoundException: No package found for authority: android.resource://com.my.package/drawable/theImage when I try to do the following in the constructor:

try {
     actualPic = MediaStore.Images.Media.getBitmap(app.getContentResolver(), theImageUri);
} catch (IOException e) {
     e.printStackTrace();
}

IMPORTANT: MainActivity, which is the class instantiating the Item object, passes a reference to itself to the Item's constructor called app, which I use to call getContentResolver method.

I read that I need to make a class that extends ContentProvider and declare it in the manifest, but it seems like a a lot to do to just get that Bitmap. Am I missing something? Is there a simpler way of getting that Bitmap retrieved or I need to create that new class?

Thanks in advance.

Philip
  • 319
  • 5
  • 13

1 Answers1

0

If you just want to retrieve a Bitmap from your resources check this: How to convert a Drawable to a Bitmap?

Community
  • 1
  • 1
9re
  • 2,408
  • 27
  • 27
  • I followed your advice and did the following: `Resources res = app.getResources(); int imgId = res.getIdentifier(fileName, "drawable", app.getPackageName()); Drawable drawable = res.getDrawable(imgId); this.actualPic = ((BitmapDrawable) drawable).getBitmap();` So with only the name of the image located on the drawable folder I could get the Bitmap I needed. Worked great. Thank you. – Philip Dec 21 '15 at 01:41