MediaStore.Images.Media.getBitmap returns System.err 在通知大图标中
MediaStore.Images.Media.getBitmap returns System.err in notification largeicon
我正在制作使用 shoutcast 流的广播应用程序。除了在通知大图标处显示播放曲目的艺术作品外,一切都适用于我的应用程序。我想使用 uri 中的艺术品。但它从不在 largeicon 上显示艺术品。
这是日志
11-10 17:28:58.624 21627-21627/****** I/Artwork:
/storage/emulated/0/******/Radio/artworks/fb7fb1d9ad.jpg
11-10 17:28:58.628 21627-21627/****** W/System.err: at ******
.Radyo.nowPlayingN(Radyo.java:684)
if(uri==null) {
Bitmap Largeicon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_for_radio);
notification.setLargeIcon(Largeicon);
}else {
try {
Log.i("Artwork", uri);
Bitmap SavedArtwork = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(uri));
notification.setLargeIcon(SavedArtwork);
} catch (IOException e) {
notification.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),R.mipmap.ic_launcher_for_radio));
e.printStackTrace();
}
}
我用这个解决了问题
Bitmap SavedArtwork = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse("file://"+uri));
public static Bitmap uriToBitmap(Context c, Uri uri) {
if (c == null && uri == null) {
return null;
}
try {
return MediaStore.Images.Media.getBitmap(c.getContentResolver(), Uri.fromFile(new File(uri.getPath())));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
我正在制作使用 shoutcast 流的广播应用程序。除了在通知大图标处显示播放曲目的艺术作品外,一切都适用于我的应用程序。我想使用 uri 中的艺术品。但它从不在 largeicon 上显示艺术品。 这是日志
11-10 17:28:58.624 21627-21627/****** I/Artwork: /storage/emulated/0/******/Radio/artworks/fb7fb1d9ad.jpg
11-10 17:28:58.628 21627-21627/****** W/System.err: at ****** .Radyo.nowPlayingN(Radyo.java:684)
if(uri==null) {
Bitmap Largeicon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_for_radio);
notification.setLargeIcon(Largeicon);
}else {
try {
Log.i("Artwork", uri);
Bitmap SavedArtwork = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(uri));
notification.setLargeIcon(SavedArtwork);
} catch (IOException e) {
notification.setLargeIcon(BitmapFactory.decodeResource(this.getResources(),R.mipmap.ic_launcher_for_radio));
e.printStackTrace();
}
}
我用这个解决了问题
Bitmap SavedArtwork = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse("file://"+uri));
public static Bitmap uriToBitmap(Context c, Uri uri) {
if (c == null && uri == null) {
return null;
}
try {
return MediaStore.Images.Media.getBitmap(c.getContentResolver(), Uri.fromFile(new File(uri.getPath())));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}