Android音乐播放器通知优先级

时间:2017-05-21 21:39:34

标签: android notifications audio-player android-music-player

目前正致力于音乐播放器,以提高我对Android开发的了解。我坚持听音乐播放器的通知。我使用RemoteView创建它并且工作正常,但唯一的问题是它不会停留在通知栏的顶部。当我收到来自Skype,Facebook等的通知时,他们最终会高于通知。在构建通知时,我应该使用什么配置来播放音乐播放器通知?这就是我到目前为止所做的:

Tools tools = new Tools();
        Bitmap bm = tools.getAlbumart(this.context,
                Library.getSongs().get(songService.getIndex()).getAlbumID());
        if (bm != null) {
            Bitmap resized = Bitmap.createScaledBitmap(bm, 100, 100, true);
            remoteViews.setImageViewBitmap(R.id.notifcation_img, resized);
        }
        bm.recycle();

        remoteViews.setTextViewText(R.id.notification_song_name,
                Library.getSongs().get(songService.getIndex()).getSongName());
        remoteViews.setTextViewText(R.id.notification_artist,
                Library.getSongs().get(songService.getIndex()).getArtistName());

        pauseOrPlay(false);

        Intent resultIntent = new Intent(context, MainActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                resultIntent, 0);

        Intent pauseIntent = new Intent("PAUSEORPLAY");
        Intent fastForwardIntent = new Intent("FAST_FORWARD");
        Intent rewindIntent = new Intent("REWIND");

        PendingIntent pause = PendingIntent.getBroadcast(context, 11, pauseIntent, 0);
        PendingIntent fastforward = PendingIntent.getBroadcast(context, 12, fastForwardIntent, 0);
        PendingIntent rewind = PendingIntent.getBroadcast(context, 13, rewindIntent, 0);

        remoteViews.setOnClickPendingIntent(R.id.notification_playpause_img, pause);
        remoteViews.setOnClickPendingIntent(R.id.notification_fastforward_img, fastforward);
        remoteViews.setOnClickPendingIntent(R.id.notification_rewind_img, rewind);

        builder.setSmallIcon(R.drawable.playbutton)
                .setDefaults(Notification.PRIORITY_MAX)
                .setOngoing(true)
                .setContentIntent(contentIntent)
                .setPriority(Notification.PRIORITY_MAX)
                .setVibrate(new long[]{0l})
                .setCustomContentView(remoteViews);


        notifManager.notify(1, builder.build());

0 个答案:

没有答案