1

We are downloading images for Android TV global search from server, manipulating them, storing them in the cache and providing file Uri for the global search. Everything displays correctly on a real device, but on an emulator, for some reason, we are getting this exception (and our image is not displayed as a thumbnail):

com.google.android.katniss E/DrawableLoader: FileNotFoundException during openInputStream for uri: file:///storage/emulated/0/Android/data/{package_name}/cache/{image_name}.png

In the cursor, for SUGGEST_COLUMN_RESULT_CARD_IMAGE field, we return Uri obtained from this method:

//...
//image manipulation
//...
File file = new File(getContext().getExternalCacheDir(), "image" + name + id + ".jpeg");
FileOutputStream fileOutputStream = new FileOutputStream(file);
        background.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
uriImage = Uri.fromFile(file);
fileOutputStream.close();
bitmap.recycle();
background.recycle();
return uriImage;

We have to provide a lot of different images as thumbnails for Android TV Global search results, so it's impractical to have all these images as resources in project.

This works correctly on Asus Nexus Player, Android 7.1.2 and few other TVs with different Android versions. It fails to work on Android TV emulator, Android 7.0

Filip
  • 146
  • 1
  • 5
  • This might help: http://stackoverflow.com/questions/34000860/why-sometime-it-throws-filenotfoundexception – abielita Apr 30 '17 at 18:29
  • Thanks, but none of the suggested answers is the solution for this problem. – Filip May 02 '17 at 11:32
  • Hi, Filip, I'm dealing with uri for SUGGEST_COLUMN_RESULT_CARD_IMAGE but it doesn´t work. I get the uri from the cached image with Glide and I pass the uri.toString() to the SUGGEST_COLUMN_RESULT_CARD_IMAGE colum. I've checked if file with this uri exists but it doesn´t, some advice? – Erik Medina Jun 01 '17 at 07:27
  • @ErikMedina You shouldn't pass String for this column, rather URI. This is from official documentation: "The data in the column must be a resource ID of a drawable, or a URI in one of the following formats: content (SCHEME_CONTENT) android.resource (SCHEME_ANDROID_RESOURCE) file (SCHEME_FILE)" Regarding the file not existing, I'm not sure why you aren't able to find it. I am manually downloading it with Picasso, storing it in the cache dir and passing Uri.fromFile() to the column and it works fine. – Filip Jun 02 '17 at 07:55
  • I tried to pass URI but put() method only accepts primitive types. I've checked that my cached image exists (because I got it to load in a ImageView) so I think that the problem is that the permission to access to the cached image is not granted. – Erik Medina Jun 05 '17 at 11:29
  • @ErikMedina I'm not sure where do you use put() method. I'm creating a MatrixCursor and adding item info with cursor.newRow().add(int id).add(URI uri).add... – Filip Jun 06 '17 at 12:44
  • Oh! Ok, thank you. Now I can pass the uri. Before I was using a database to provide data to global search. The bad thing is that my cached image is not showed yet. I have no idea what's happening. – Erik Medina Jun 07 '17 at 12:57

0 Answers0