|
@@ -71,7 +71,7 @@ public class MainActivity extends ReactActivity {
|
|
|
// intent.putExtra("triggerTime", System.currentTimeMillis() + 10000); // 60秒后触发
|
|
// intent.putExtra("triggerTime", System.currentTimeMillis() + 10000); // 60秒后触发
|
|
|
// intent.putExtra("channel","CHANNEL_ID");
|
|
// intent.putExtra("channel","CHANNEL_ID");
|
|
|
// startService(intent);
|
|
// startService(intent);
|
|
|
- scheduleNotificationAfter(getContext(),10,"hellow","world");
|
|
|
|
|
|
|
+// scheduleNotificationAfter(getContext(),10,"hellow","world");
|
|
|
|
|
|
|
|
return reactRootView;
|
|
return reactRootView;
|
|
|
}
|
|
}
|
|
@@ -85,7 +85,7 @@ public class MainActivity extends ReactActivity {
|
|
|
|
|
|
|
|
public void scheduleNotificationAfter(Context context, long delaySeconds, String title, String body) {
|
|
public void scheduleNotificationAfter(Context context, long delaySeconds, String title, String body) {
|
|
|
// 1. 创建通知渠道 (Android 8.0 及以上版本需要)
|
|
// 1. 创建通知渠道 (Android 8.0 及以上版本需要)
|
|
|
- createNotificationChannel(context);
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// 2. 创建通知意图
|
|
// 2. 创建通知意图
|
|
|
Intent intent = new Intent(context, AlarmReceiver.class);
|
|
Intent intent = new Intent(context, AlarmReceiver.class);
|
|
@@ -98,17 +98,28 @@ public class MainActivity extends ReactActivity {
|
|
|
|
|
|
|
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 9);
|
|
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
|
|
|
|
+ calendar.setTimeInMillis(System.currentTimeMillis());
|
|
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 11);
|
|
|
|
|
+ calendar.set(Calendar.MINUTE, 42);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果当前时间已经超过 设定时间,则设置为明天
|
|
|
|
|
+ if (calendar.getTimeInMillis() <= System.currentTimeMillis()) {
|
|
|
|
|
+ calendar.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 4. 使用 AlarmManager 调度通知
|
|
// 4. 使用 AlarmManager 调度通知
|
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
|
|
|
|
|
+ alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
|
|
|
|
|
+ AlarmManager.INTERVAL_DAY, pendingIntent);
|
|
|
|
|
+
|
|
|
// alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
|
// alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
|
|
// SystemClock.elapsedRealtime() + delaySeconds * 1000,
|
|
// SystemClock.elapsedRealtime() + delaySeconds * 1000,
|
|
|
// pendingIntent);
|
|
// pendingIntent);
|
|
|
- alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
|
|
|
|
|
- AlarmManager.INTERVAL_DAY, pendingIntent);
|
|
|
|
|
|
|
+// alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
|
|
|
|
|
+// 10*1000, pendingIntent);
|
|
|
|
|
+// alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),pendingIntent);
|
|
|
|
|
+// alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+10*1000,
|
|
|
|
|
+// pendingIntent);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void scheduleDailyReminder(Context context) {
|
|
public void scheduleDailyReminder(Context context) {
|