手动发送心跳

serial
BlueMatthew 1 year ago
parent 7908fd8470
commit 1b954e4edd

@ -61,6 +61,8 @@
<uses-permission
android:name="android.permission.START_ACTIVITIES_FROM_BACKGROUND"
tools:ignore="ProtectedPermissions" />
<!-- WiFi AP startTethering -->
<uses-permission android:name="android.permission.TETHER_PRIVILEGED" tools:ignore="ProtectedPermissions" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.hardware.usb.accessory"/>

@ -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());
}
});

@ -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) {

Loading…
Cancel
Save