public NotificationCompat.Builder buildLocalNotification(Context context, PendingIntent pendingIntent, AppointmentModel appointmentModel) {
String channelId = "Appoinment Reminder";
Log.e("@@ChannelId", channelId);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Appoinment Reminder")
.setContentText("Your appointment with "+appointmentModel.getContact() +" at "+ appointmentModel.getDate1()+" "+appointmentModel.getTime())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@SuppressLint("WrongConstant") NotificationChannel channel = new NotificationChannel(channelId, "Appoinment Reminder", NotificationManager.IMPORTANCE_DEFAULT);
manager.createNotificationChannel(channel);
}
manager.notify(NotificationID.getID(), builder.build());
return builder;
}
intentToRepeat.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivities(context, NotificationID.getID(), new Intent[] {backIntent, intentToRepeat}, PendingIntent.FLAG_UPDATE_CURRENT);
buildLocalNotification(context, pendingIntent, appointmentModelList.get(i)).build();
приведенный выше код работает для уведомления, но не имеет представления об экранном напоминании
WindowManager windowManager2 = (WindowManager) App.getAppContext().getSystemService(WINDOW_SERVICE);
LayoutInflater layoutInflater=(LayoutInflater) App.getAppContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view=layoutInflater.inflate(R.layout.window_popup_medicine, null);
WindowManager.LayoutParams
params= null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
}
params.gravity=Gravity.CENTER|Gravity.CENTER;
params.x=0;
params.y=0;
windowManager2.addView(view, params);