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