简体   繁体   English

MediaStore.Images.Media.getBitmap在通知largeicon中返回System.err

[英]MediaStore.Images.Media.getBitmap returns System.err in notification largeicon

I am making radio app which uses shoutcast stream. 我正在制作使用广播流的广播应用程序。 Everything works well with my app except showing artwork of playing track at notification large icon. 一切都与我的应用程序兼容,但在通知大图标上显示播放曲目的图稿。 I want to use artwork from uri. 我想使用uri的艺术品。 But it never shows the artwork at largeicon. 但是它永远不会在largeicon上显示艺术品。 Here is the log 这是日志

11-10 17:28:58.624 21627-21627/****** I/Artwork: /storage/emulated/0/******/Radio/artworks/fb7fb1d9ad.jpg 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) 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM