以下是应用程序级别build.gradle文件中使用的库:
implementation 'com.android.support:appcompat-v7:28.0.0'
以下是通知代码:
Intent snoozeIntent = new Intent(getApplicationContext(), MyBroadcastReceiver.class);
snoozeIntent.setAction(MY_ACTION);
snoozeIntent.putExtra("EXTRA_NOTIFICATION_ID", 0);
PendingIntent snoozePendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, snoozeIntent, 0);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(),"Hello")
.setPriority(Notification.PRIORITY_MAX)
.setWhen(0)
.setShowWhen(false)
.setContentTitle("My Custom Notification")
.setContentText("Hello Custom")
.setSmallIcon(R.drawable.ic_battery_charging_full_white_24dp)
.addAction(android.R.drawable.ic_input_add,"Action 1",snoozePendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(1,notificationBuilder.build());