Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TV全局搜索缩略图-FileNotFoundException_Android_Filenotfoundexception_Android Tv - Fatal编程技术网

Android TV全局搜索缩略图-FileNotFoundException

Android TV全局搜索缩略图-FileNotFoundException,android,filenotfoundexception,android-tv,Android,Filenotfoundexception,Android Tv,我们正在从服务器下载Android TV全局搜索的图像,对它们进行操作,将它们存储在缓存中,并为全局搜索提供文件Uri。在真实设备上,所有内容都能正确显示,但在模拟器上,由于某些原因,我们会遇到此异常(并且我们的图像不会显示为缩略图): 在光标中,对于“建议\列\结果\卡片\图像”字段,我们返回从该方法获得的Uri: //... //image manipulation //... File file = new File(getContext().getExternalCacheDir(),

我们正在从服务器下载Android TV全局搜索的图像,对它们进行操作,将它们存储在缓存中,并为全局搜索提供文件Uri。在真实设备上,所有内容都能正确显示,但在模拟器上,由于某些原因,我们会遇到此异常(并且我们的图像不会显示为缩略图):

在光标中,对于“建议\列\结果\卡片\图像”字段,我们返回从该方法获得的Uri:

//...
//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;
我们必须为Android TV全球搜索结果提供许多不同的图像作为缩略图,所以在项目中使用所有这些图像作为资源是不切实际的

这在华硕Nexus播放器、安卓7.1.2和其他几个安卓版本的电视上都能正常工作。
它在Android TV emulator、Android 7.0上无法工作这可能会有帮助:谢谢,但没有一个建议的答案是解决这个问题的方法。嗨,菲利普,我正在处理建议列结果卡图像的uri,但它不工作。我使用Glide从缓存的图像中获取uri,并将uri.toString()传递给建议列、结果卡和图像列。我已经检查了这个uri的文件是否存在,但它不存在,有什么建议吗?@ErikMedina您不应该为这个列传递字符串,而应该传递uri。这来自官方文档:“列中的数据必须是可绘图的资源ID,或以下格式之一的URI:content(SCHEME_content)android.resource(SCHEME_android_resource)file(SCHEME_file)”关于不存在的文件,我不确定您为什么找不到它。我用毕加索手动下载它,将它存储在缓存目录中,并将Uri.fromFile()传递到列中,它工作正常。我尝试传递Uri,但put()方法只接受基元类型。我已检查缓存图像是否存在(因为我已将其加载到ImageView中),因此我认为问题在于未授予访问缓存图像的权限。这可能会有所帮助:谢谢,但建议的答案都不是解决此问题的方法。嗨,Filip,我正在处理建议、列、结果、卡片和图像的uri,但它不起作用。我使用Glide从缓存的图像中获取uri,并将uri.toString()传递给建议列、结果卡和图像列。我已经检查了这个uri的文件是否存在,但它不存在,有什么建议吗?@ErikMedina您不应该为这个列传递字符串,而应该传递uri。这来自官方文档:“列中的数据必须是可绘图的资源ID,或以下格式之一的URI:content(SCHEME_content)android.resource(SCHEME_android_resource)file(SCHEME_file)”关于不存在的文件,我不确定您为什么找不到它。我用毕加索手动下载它,将它存储在缓存目录中,并将Uri.fromFile()传递到列中,它工作正常。我尝试传递Uri,但put()方法只接受基元类型。我已经检查了缓存图像是否存在(因为我让它加载到ImageView中),所以我认为问题在于没有授予访问缓存图像的权限。
//...
//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;