[英]Android MediaStore.Images.Media.getBitmap returns error
[英]MediaStore.Images.Media.getBitmap returns System.err in notification largeicon
我正在制作使用廣播流的廣播應用程序。 一切都與我的應用程序兼容,但在通知大圖標上顯示播放曲目的圖稿。 我想使用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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.