Mobile_Application_Developm.../AirKoality/app/src/main/java/at/fhj/airkoality/service/LocationService.java

72 lines
1.7 KiB
Java

package at.fhj.airkoality.service;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import at.fhj.airkoality.AirKoalityApplication;
import at.fhj.airkoality.R;
import at.fhj.airkoality.ui.activity.MainActivity;
public class LocationService extends Service {
private String TAG = "LocationService";
private Notification notification;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "Service started");
startForeground(1337,notification);
return START_STICKY;
}
@Override
public void onCreate(){
Log.d(TAG, "Service created");
super.onCreate();
setupNotification();
}
@Override
public void onDestroy(){
Log.d(TAG, "Service destroyed");
super.onDestroy();
}
private void setupNotification() {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification = new NotificationCompat.Builder(this, AirKoalityApplication.CHANNEL_ID)
.setContentText("Updating location")
.setContentTitle("AirKoality-lab Location Service")
.setSmallIcon(R.drawable.ic_phone_android_black_24dp)
.setContentIntent(pendingIntent).build();
}
}