特定日期和时间的 Android 警报通知

时间:2021-05-11 02:06:03

标签: android-studio

每当用户单击按钮时,我都会创建一个通知。但我希望通知出现在特定的日期和时间。

Toast.makeText(MainPage.this, "ALARM SET!", Toast.LENGTH_SHORT).show();
             String message = "This is notification example";
             NotificationCompat.Builder builder = new NotificationCompat.Builder(MainPage.this, "My Notification")
                     .setSmallIcon(R.drawable.ic_message)
                     .setContentTitle("New Notification")
                     .setContentText(message)
                     .setAutoCancel(true);

             Intent intent = new Intent(MainPage.this, TransactionTab.class);
             intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
             intent.putExtra("message",message);

             PendingIntent pendingIntent = PendingIntent.getActivity(MainPage.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
             builder.setContentIntent(pendingIntent);

             NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
             notificationManager.notify(0,builder.build());

0 个答案:

没有答案
相关问题