我想關閉通知刷卡,但它只是不會關閉。我試圖設置正確的標誌以及設置OnGoing爲false,但我沒有運氣。關閉通知刷卡不工作
這是我的代碼有:
Notification notification = new Notification.Builder(getBaseContext())
.setSmallIcon(R.drawable.appicon)
.setContentTitle("My notification")
.setContent(remoteViews)
.setAutoCancel(true)
.setOngoing(false)
.build();
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
// Additional code
Intent playpause = new Intent();
playpause.setAction("com.eciflow.project.pause");
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 1, playpause, PendingIntent.FLAG_CANCEL_CURRENT);
Intent stop = new Intent();
stop.setAction("com.eciflow.project.stop");
PendingIntent stopI = PendingIntent.getBroadcast(getApplicationContext(), 1, stop, PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setImageViewResource(R.id.playpause, R.drawable.pauseradio);
remoteViews.setImageViewResource(R.id.stop, R.drawable.stopradio);
remoteViews.setOnClickPendingIntent(R.id.playpause, pi);
remoteViews.setOnClickPendingIntent(R.id.stop, stopI);
remoteViews.setTextViewText(R.id.title, "Playing");
remoteViews.setTextViewText(R.id.text, param2);
remoteViews.setTextColor(R.id.title, getResources().getColor(android.R.color.holo_blue_dark));
remoteViews.setTextColor(R.id.text, getResources().getColor(android.R.color.holo_blue_dark));
startForeground(250, notification);
我在玩音樂從流背景...
任何想法,爲什麼發生這種情況?如果還有其他選擇,我也願意改變結構。
謝謝!
嘗試使用「NotificationCompat」而不是「通知」。 –