Skip to content

Commit

Permalink
fixed possible issue reported by CrashLytics
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed Feb 28, 2024
1 parent 3dc7c63 commit 9058eb0
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ public class RecordTrackReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
Logger.d(TAG, "[BLE] StartServiceReceiver: onReceive..");
Intent service = new Intent(context, RecordTrackService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
String permission = Manifest.permission.ACCESS_BACKGROUND_LOCATION;
int res = context.checkCallingOrSelfPermission(permission);
boolean cp_bg_loc = (res == PackageManager.PERMISSION_GRANTED);
if (!cp_bg_loc) Logger.w(TAG, "[BLE] StartServiceReceiver: FAILED!");
if (!cp_bg_loc) return;
try {
Logger.d(TAG, "[BLE] StartServiceReceiver: onReceive..");
Intent service = new Intent(context, RecordTrackService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
String permission = Manifest.permission.ACCESS_BACKGROUND_LOCATION;
int res = context.checkCallingOrSelfPermission(permission);
boolean cp_bg_loc = (res == PackageManager.PERMISSION_GRANTED);
if (!cp_bg_loc) Logger.w(TAG, "[BLE] StartServiceReceiver: FAILED!");
if (!cp_bg_loc) return;
}
ContextCompat.startForegroundService(context, service);
} else {
context.startService(service);
}
ContextCompat.startForegroundService(context, service);
} else {
context.startService(service);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 9058eb0

Please sign in to comment.