From 1b954e4eddf4affe44a19f50f3b1378e4f77a6c8 Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Mon, 1 Jan 2024 22:01:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=8F=91=E9=80=81=E5=BF=83?= =?UTF-8?q?=E8=B7=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 2 ++ .../main/java/com/xypower/mpapp/MainActivity.java | 6 +----- .../java/com/xypower/mpapp/MicroPhotoService.java | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 20dfbad6..77f9cc67 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -61,6 +61,8 @@ + + diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java index ab84247d..5dd13607 100644 --- a/app/src/main/java/com/xypower/mpapp/MainActivity.java +++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java @@ -427,11 +427,7 @@ public class MainActivity extends AppCompatActivity { binding.btnSendHb.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - - // String path = "/sdcard/com.xypower.mpapp/packages/app.apk"; - // SysApi.installApk(getApplicationContext(), path, v.getContext().getPackageName(), true); - // Context context = MainActivity.this.getApplicationContext(); - // MicroPhotoService.sendMessage(context, MicroPhotoService.MSG_WHAT_SENDING_HB, 0); + MicroPhotoService.sendHeartbeat(getApplicationContext()); } }); diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index e210e9c3..8700d890 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -91,6 +91,7 @@ public class MicroPhotoService extends Service { private static final String ACTION_HEARTBEAT = "ACT_HB"; private static final String ACTION_TAKE_PHOTO = "ACT_TP"; private static final String ACTION_TAKE_PHOTO_MANUALLY = "ACT_TP_M"; + private static final String ACTION_HEARTBEAT_MANUALLY = "ACT_HB_M"; private static final String ACTION_TIMEOUT = "ACT_TIMEOUT"; private static final String EXTRA_PARAM_CHANNEL = "Channel"; private static final String EXTRA_PARAM_PRESET = "Preset"; @@ -158,6 +159,7 @@ public class MicroPhotoService extends Service { intentFilter.addAction(ACTION_TAKE_PHOTO); intentFilter.addAction(ACTION_TIMEOUT); intentFilter.addAction(ACTION_TAKE_PHOTO_MANUALLY); + intentFilter.addAction(ACTION_HEARTBEAT_MANUALLY); intentFilter.addAction(ACTION_MSG_BROADCAST); registerReceiver(mAlarmReceiver, intentFilter); @@ -295,6 +297,9 @@ public class MicroPhotoService extends Service { long baseTime = nowTs - startTime; mService.registerCaptureSchedule(startTime, baseTime); + }if (TextUtils.equals(ACTION_HEARTBEAT_MANUALLY, action)) { + Log.i(TAG, "HB Timer Fired ACTION=" + action); + mService.sendHeartbeat(mService.mNativeHandle); } else if (TextUtils.equals(ACTION_TAKE_PHOTO_MANUALLY, action)) { int channel = intent.getIntExtra(EXTRA_PARAM_CHANNEL, 0); int preset = intent.getIntExtra(EXTRA_PARAM_PRESET, 0); @@ -536,6 +541,16 @@ public class MicroPhotoService extends Service { registerPhotoTimer(context, channel, preset, 0, 0, schedules); } + public static void sendHeartbeat(Context context) { + + Intent alarmIntent = new Intent(); + alarmIntent.setAction(ACTION_HEARTBEAT_MANUALLY); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); + + AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); + alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), pendingIntent); + } + @Override public int onStartCommand(Intent intent, int flags, int startId) {