forked from upstream-mirrors/OpenTracks
TrackRecordingService: start via ServiceCompat.
This commit is contained in:
@@ -133,6 +133,7 @@ dependencies {
|
|||||||
implementation 'androidx.gridlayout:gridlayout:1.0.0'
|
implementation 'androidx.gridlayout:gridlayout:1.0.0'
|
||||||
implementation 'com.google.android.material:material:1.11.0'
|
implementation 'com.google.android.material:material:1.11.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
|
implementation 'androidx.core:core:1.12.0'
|
||||||
implementation 'androidx.core:core-splashscreen:1.0.1'
|
implementation 'androidx.core:core-splashscreen:1.0.1'
|
||||||
implementation 'androidx.mediarouter:mediarouter:1.6.0'
|
implementation 'androidx.mediarouter:mediarouter:1.6.0'
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.core.app.ServiceCompat;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
@@ -111,7 +112,7 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
recordingDataObservable = new MutableLiveData<>(NOT_RECORDING);
|
recordingDataObservable = new MutableLiveData<>(NOT_RECORDING);
|
||||||
|
|
||||||
trackPointCreator = new TrackPointCreator(this);
|
trackPointCreator = new TrackPointCreator(this);
|
||||||
trackRecordingManager = new TrackRecordingManager(this, trackPointCreator, this , handler);
|
trackRecordingManager = new TrackRecordingManager(this, trackPointCreator, this, handler);
|
||||||
|
|
||||||
voiceAnnouncementManager = new VoiceAnnouncementManager(this);
|
voiceAnnouncementManager = new VoiceAnnouncementManager(this);
|
||||||
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
||||||
@@ -213,19 +214,15 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
|||||||
Log.i(TAG, "startSensors");
|
Log.i(TAG, "startSensors");
|
||||||
wakeLock = SystemUtils.acquireWakeLock(this, wakeLock);
|
wakeLock = SystemUtils.acquireWakeLock(this, wakeLock);
|
||||||
trackPointCreator.start(this, handler);
|
trackPointCreator.start(this, handler);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
if (!PermissionRequester.RECORDING.hasPermission(this)) {
|
if (!PermissionRequester.RECORDING.hasPermission(this)) {
|
||||||
Toast.makeText(this, R.string.permission_recording_failed, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.permission_recording_failed, Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.setGPSonlyStarted(this), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION + ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE);
|
|
||||||
} else {
|
|
||||||
startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.setGPSonlyStarted(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ServiceCompat.startForeground(this, TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.setGPSonlyStarted(this), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION + ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endCurrentTrack() {
|
public void endCurrentTrack() {
|
||||||
|
|||||||
Reference in New Issue
Block a user