Fix backround launch of location service
This commit is contained in:
parent
f4b6d7a332
commit
5ab34cd32f
@ -92,7 +92,11 @@ class LocationUtils {
|
|||||||
|
|
||||||
static void requestLocationOnce(Context context) {
|
static void requestLocationOnce(Context context) {
|
||||||
Intent myService = new Intent(context, LocationRequestService.class);
|
Intent myService = new Intent(context, LocationRequestService.class);
|
||||||
context.startService(myService);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
context.startForegroundService(myService);
|
||||||
|
} else {
|
||||||
|
context.startService(myService);
|
||||||
|
}
|
||||||
//OneTimeWorkRequest oneTimeWork = new OneTimeWorkRequest.Builder(LocationUpdatesWorker.class)
|
//OneTimeWorkRequest oneTimeWork = new OneTimeWorkRequest.Builder(LocationUpdatesWorker.class)
|
||||||
// .build();
|
// .build();
|
||||||
//WorkManager.getInstance(context).enqueueUniqueWork(LocationUtils.LOCATION_REQUEST_NAME, ExistingWorkPolicy.REPLACE, oneTimeWork);
|
//WorkManager.getInstance(context).enqueueUniqueWork(LocationUtils.LOCATION_REQUEST_NAME, ExistingWorkPolicy.REPLACE, oneTimeWork);
|
||||||
|
@ -22,11 +22,14 @@ import com.google.firebase.messaging.RemoteMessage;
|
|||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.util.Log;
|
||||||
import android.webkit.URLUtil;
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
|
|
||||||
public class MessagingService extends FirebaseMessagingService {
|
public class MessagingService extends FirebaseMessagingService {
|
||||||
|
|
||||||
|
private static final String TAG = MessagingService.class.getSimpleName();
|
||||||
|
|
||||||
public static final String NOTIFICATION_ACTION_BROADCAST = "com.keyboardcrumbs.hassclient.haNotificationAction";
|
public static final String NOTIFICATION_ACTION_BROADCAST = "com.keyboardcrumbs.hassclient.haNotificationAction";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,6 +56,7 @@ public class MessagingService extends FirebaseMessagingService {
|
|||||||
messageBody = data.get("body");
|
messageBody = data.get("body");
|
||||||
}
|
}
|
||||||
if (messageBody != null && messageBody.equals(LocationUtils.REQUEST_LOCATION_NOTIFICATION)) {
|
if (messageBody != null && messageBody.equals(LocationUtils.REQUEST_LOCATION_NOTIFICATION)) {
|
||||||
|
Log.d(TAG, "Location update request received");
|
||||||
LocationUtils.requestLocationOnce(this);
|
LocationUtils.requestLocationOnce(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user