问题描述
我正在将存储在设备存储中的图像显示到应用程序上的图像视图和小部件上的图像视图中,它在应用程序上运行良好,但在小部件上它没有显示出来,我在运行选项卡上收到这两个错误: E/libEGL:libcolorx-loader.so 和 E/OplusCustomizeRestrictionManager 的文件路径无效:sInstance 为空,启动一个新的 sInstance
如果有人能告诉我为什么它不起作用,那将非常有帮助。
应用上的图像查看代码:
private void saveImage(Bitmap image,File storageDir,String imageFileName) throws IOException {
Context context = getApplicationContext();
SharedPreferences setting = getSharedPreferences("PlaylistWidgetPreferences",MODE_PRIVATE);
SharedPreferences.Editor prefEditor = setting.edit();
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE,"any_picture_name");
values.put(MediaStore.Images.Media.DESCRIPTION,"test Image taken");
values.put(MediaStore.Images.Media.MIME_TYPE,"image/jpeg");
Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);
prefEditor.putString("thumbnailPath",String.valueOf(uri));
prefEditor.apply();
Toast.makeText(getApplicationContext(),uri.toString(),Toast.LENGTH_SHORT).show();
OutputStream outstream;
try {
outstream = getContentResolver().openOutputStream(uri);
image.compress(Bitmap.CompressFormat.JPEG,100,outstream);
outstream.close();
Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printstacktrace();
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
imageView.setimageBitmap(getBitmapFromUri(uri));
}
private Bitmap getBitmapFromUri(Uri uri) throws IOException {
ParcelFileDescriptor parcelFileDescriptor =
getContentResolver().openFileDescriptor(uri,"r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
return image;
}
这是小部件上的情况:
@Override
public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds) {
Log.d("1","1In OnUpdate.");
SharedPreferences settings = context.getSharedPreferences("PlaylistWidgetPreferences",Context.MODE_PRIVATE);
thumbnailPath = settings.getString("thumbnailPath","Hi");
Log.d("URI : ",thumbnailPath);
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),R.layout.playlist);
try {
remoteViews.setimageViewBitmap(R.id.videoThumbnail,getBitmapFromUri(thumbnailPath,context));
} catch (IOException e) {
e.printstacktrace();
}
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context,appWidgetManager,appWidgetId);
}
}
private Bitmap getBitmapFromUri(String uri,Context context) throws IOException {
getContentResolver().openFileDescriptor(uri,"r");
ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver().openFileDescriptor(Uri.parse(uri),"r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
return image;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)