|
|
@@ -8,6 +8,7 @@ import android.content.Intent;
|
|
|
import android.graphics.Color;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.os.SystemClock;
|
|
|
import android.util.Log;
|
|
|
|
|
|
@@ -26,6 +27,9 @@ import java.util.Calendar;
|
|
|
|
|
|
public class MainActivity extends ReactActivity {
|
|
|
|
|
|
+ private Handler handler;
|
|
|
+ private Runnable runnable;
|
|
|
+
|
|
|
private static final String CHANNEL_ID = "local_notification_channel";
|
|
|
private static final String CHANNEL_NAME = "Daily Reminder";
|
|
|
private static final String CHANNEL_DESCRIPTION = "Daily reminder notification at 9:00 AM";
|
|
|
@@ -49,25 +53,54 @@ public class MainActivity extends ReactActivity {
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState){
|
|
|
super.onCreate(null);
|
|
|
+ checkNotification(getIntent());
|
|
|
+// String action = getIntent().getAction();
|
|
|
+// System.out.println("notification receive action action:"+action);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onNewIntent(Intent intent) {
|
|
|
super.onNewIntent(intent);
|
|
|
+// System.out.println("notification receive action 疯狂加载中open");
|
|
|
+
|
|
|
+ checkNotification(intent);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkNotification(Intent intent){
|
|
|
if ("START_TIMER_NOW".equals(intent.getAction())||
|
|
|
"PICK_EARLIER_START".equals(intent.getAction())||
|
|
|
"END_TIMER_NOW".equals(intent.getAction())||
|
|
|
"PICK_EARLIER_END".equals(intent.getAction())
|
|
|
) {
|
|
|
- WritableMap payload = Arguments.createMap();
|
|
|
- payload.putString("category_id",intent.getStringExtra("category_id"));
|
|
|
- payload.putString("action_id",intent.getAction());
|
|
|
- payload.putString("id",intent.getStringExtra("id"));
|
|
|
- //category_id, action_id,id
|
|
|
- getReactInstanceManager().
|
|
|
- getCurrentReactContext().
|
|
|
- getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).
|
|
|
- emit("notificationReceive",payload);
|
|
|
+ handler = new Handler();
|
|
|
+ runnable = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ // 每秒检查 GlobalVariable.isValueTrue 的值
|
|
|
+ System.out.println("notification receive action 疯狂加载中");
|
|
|
+ if (GlobalVariable.rnLoaded) {
|
|
|
+ // 如果为 true,停止计时器并使用 receivedIntent 对象
|
|
|
+ handler.removeCallbacks(this);
|
|
|
+
|
|
|
+ WritableMap payload = Arguments.createMap();
|
|
|
+ payload.putString("category_id",intent.getStringExtra("category_id"));
|
|
|
+ payload.putString("action_id",intent.getAction());
|
|
|
+ payload.putString("id",intent.getStringExtra("id"));
|
|
|
+ //category_id, action_id,id
|
|
|
+ getReactInstanceManager().
|
|
|
+ getCurrentReactContext().
|
|
|
+ getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).
|
|
|
+ emit("notificationReceive",payload);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ handler.postDelayed(this, 1000); // 每隔 1 秒执行一次
|
|
|
+ }
|
|
|
+ };
|
|
|
+ handler.post(runnable);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|