使用此代码,我想单击一个按钮并显示一个通知。问题是当我在模拟器api 26+中进行测试时,单击我的按钮时没有出现。在api中,以下26正常显示,没有问题。
btNotify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notification();
}
});
public void notification() {
RemoteViews remoteViews = new
RemoteViews(getApplicationContext().getPackageName(),R.layout.notification_collapsed);
remoteViews.setTextViewText(R.id.title, "Atividade");
remoteViews.setTextViewText(R.id.act, activity);
remoteViews.setChronometer(R.id.timer, chronometer.getBase(), chronometer.getFormat(), !running);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notification")
.setSmallIcon(R.drawable.ic_baseline_access_time_24)
.setContent(remoteViews)
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert notifManager != null;
notifManager.notify(1, builder.build());
}