'image get displayed on app but not on widget remoteViews
i'm displaying image stored on device storage to image view on app and in imageview on widget, it works fine on app but on widget it's not getting displayed and i'm getting these two errors on run tab : E/libEGL: Invalid file path for libcolorx-loader.so and E/OplusCustomizeRestrictionManager: sInstance is null, start a new sInstance
if anyone can tell me why it's not working it would be really helpful.
imageview code on app :
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;
}
here is how it's on widget :
@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;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|