diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 720b42c..02a0988 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,10 @@
+
+
+
+
+ android:exported="true"
+ android:foregroundServiceType="location"
+ />
= Build.VERSION_CODES.Q) {
+ NotificationChannel notificationChannel = new NotificationChannel(
+ "Foreground",
+ "Foreground",
+ NotificationManager.IMPORTANCE_DEFAULT
+ );
+ NotificationManager notificationManager = getSystemService(NotificationManager.class);
+ notificationManager.createNotificationChannel(notificationChannel);
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(this, notificationChannel.getId());
+ builder.setSmallIcon(R.drawable.ic_launcher_foreground);
+ builder.setContentText("Started service in foreground.");
+
+ ServiceCompat.startForeground(this,3784583, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);
+ }
+
LocationDatabase database = Room
.databaseBuilder(getApplicationContext(), LocationDatabase.class, "location")
.fallbackToDestructiveMigration()
diff --git a/app/src/main/java/com/proculite/logmylocation/MainActivity.java b/app/src/main/java/com/proculite/logmylocation/MainActivity.java
index 5511f1d..a47be33 100644
--- a/app/src/main/java/com/proculite/logmylocation/MainActivity.java
+++ b/app/src/main/java/com/proculite/logmylocation/MainActivity.java
@@ -26,7 +26,7 @@ public class MainActivity extends AppCompatActivity implements LocationListener,
super.onCreate(savedInstanceState);
Intent serviceIntent = new Intent(this, LocationLoggingService.class);
- startService(serviceIntent);
+ startForegroundService(serviceIntent);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);