【发布时间】:2018-12-23 17:03:59
【问题描述】:
我已阅读有关此问题的大多数问题/答案,但我的通知仍未显示。
我的广播接收器被调用,但没有任何反应。没有错误消息也没有异常。这是我的代码:
public class AlarmReceiver extends BroadcastReceiver {
private static int notificationId = 0;
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 101, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(
context, "mychannel")
.setSmallIcon(R.drawable.icon_awake)
.setContentTitle("MyAlarm")
.setContentText("Something")
.setAutoCancel(false)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent);
notificationManager.notify(notificationId++, mNotifyBuilder.build());
}
}
【问题讨论】:
标签: android android-intent notifications android-8.0-oreo