gpt4 book ai didi

android - 通知按钮不显示

转载 作者:行者123 更新时间:2023-11-29 14:32:19 39 4
gpt4 key购买 nike

正在关注 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
}
}

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

最佳答案

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

关于android - 通知按钮不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18106384/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com