通知按钮未显示

时间:2013-08-07 14:40:38

标签: android button notifications

this指南和其他在线讨论后,我已经使用.addAction方法显示了这些代码,我的通知中有按钮:

@SuppressLint("NewApi")
    public void generateNotificationSong()
    {
        if(android.os.Build.VERSION.SDK_INT >= 11){
            Notification.Builder builder = new Notification.Builder(this);
            builder.setSmallIcon(R.drawable.ic_launcher);
            builder.setContentTitle(songsList.get(currentSongIndex).getTitle());
            builder.setContentText("Next: " + songsList.get(getNextSong()).getTitle());
            builder.setOngoing(true); //E' in corso
            builder.setAutoCancel(true);


            //intent con activity che devo aprire (la corrente)
            Intent thisintent = getIntent();
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, thisintent, PendingIntent.FLAG_UPDATE_CURRENT);


            //Aggiungo i bottoni alla notifica se android è > 4.1
            if(android.os.Build.VERSION.SDK_INT >= 16)
            {
                Log.v("A", "CIAO");
                Intent prevIntent = new Intent();
                prevIntent.setAction("prec");
                PendingIntent pendingPrev = PendingIntent.getBroadcast(this, 123, prevIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                Intent nextIntent = new Intent();
                nextIntent.setAction("next");
                PendingIntent pendingNext = PendingIntent.getBroadcast(this, 123, nextIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                Intent pauseIntent = new Intent();
                pauseIntent.setAction("pause");
                PendingIntent pendingPause = PendingIntent.getBroadcast(this, 123, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                builder.addAction(R.drawable.btn_previous, "Previous", pendingPrev);
                builder.addAction(R.drawable.btn_pause, "Pause", pendingNext);
                builder.addAction(R.drawable.btn_next, "Next", pendingPause);
            }

            //la setto alla notifica
            builder.setContentIntent(pendingIntent);

            //infine la chiamo
            mNotify = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

            if(android.os.Build.VERSION.SDK_INT >= 16)
                mNotify.notify(001, builder.build()); //funziona meglio
            else
                mNotify.notify(001, builder.getNotification()); //deprecated
        }
    }

我得到的是没有我添加的按钮的通知,我想我错过了一些但我还没有找到解决方案

1 个答案:

答案 0 :(得分:8)

这是一个可能的原因。当存在其他通知时,Android可能会隐藏按钮,尤其是在您的手机充电时。尝试用两根手指点按通知并向下滑动。你应该能够看到你的按钮。