如何更新通知内容

时间:2017-11-20 00:09:10

标签: android notifications

我使用图书馆来获取音乐媒体元数据(mu,然后我想在通知中显示它) 我试过这个:

  Uri uri = Uri.parse(stream);
    OnNewMetadataListener ilistener = new OnNewMetadataListener() {
        @Override
        public void onNewHeaders(String stringUri, List<String> name, List<String> desc, List<String> br, List<String> genre, List<String> info) {
        }
        @Override
        public void onNewStreamTitle(String stringUri, final String streamTitle) {
            int color = ContextCompat.getColor(getApplicationContext(),R.color.black_overlay);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("Teskies (Online Radio)")
                    .setAutoCancel(false)
                    .setOngoing(true)
                    .setOnlyAlertOnce(true)
                    .setWhen( System.currentTimeMillis())
                    .setContentText("Song :"+streamTitle);
            Intent notificationIntent = new Intent(getApplicationContext(),MainActivity.class);
            PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),0,notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(contentIntent);
            NotificationManager manger = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
            builder.setColor(color);
            assert manger != null;
            Notification notification = builder.build();
            manger.notify(0,notification);

        }
    };
    AudiostreamMetadataManager.getInstance()
            .setUri(uri)
            .setOnNewMetadataListener(ilistener)
            .setUserAgent(UserAgent.WINDOWS_MEDIA_PLAYER)
            .start();

它会显示当前的音乐信息,但在下一首音乐的开头,旧音乐的标题会保留通知,但不会使用新数据进行更新。

0 个答案:

没有答案