0
votes

I'm trying to build a simple app that calls a number when I get to a location. I am using an IntentService with ResultReceiver. Everything is working fine when the app is visible, but nothing is working when the app is on the background. Notifications are not what I need. I need to make a call action. Is that even possible on API 26?

Added a service:

    @Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this,
            0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
            .setContentTitle("Example Service")
            .setContentIntent(pendingIntent)
            .build();

    startForeground(1, notification);

    mReceiver = GeoFenceHandler.mGeoFenceReceiver;
    GeofencingEvent geoFenceEvent = GeofencingEvent.fromIntent(intent);

    if (geoFenceEvent.hasError()) {
        int errorCode = geoFenceEvent.getErrorCode();
        deliverResultToReceiver(FAILURE_RESULT, "Error" + errorCode);

    } else {
        int transitionType = geoFenceEvent.getGeofenceTransition();

        //User enter transition
        if (Geofence.GEOFENCE_TRANSITION_ENTER == transitionType) {
            deliverResultToReceiver(SUCCESS_RESULT, ENTER_AREA);

            //User exit transition
        } else if (Geofence.GEOFENCE_TRANSITION_EXIT == transitionType) {
            deliverResultToReceiver(SUCCESS_RESULT, LEFT_AREA);
        }
    }

    stopSelf();

    return START_NOT_STICKY;
}

But still, nothing happens on background.

Thank you.

1
e"but nothing is working when the app is on the background." what EXACTLY is not working?Marian Paździoch

1 Answers

1
votes

You need to make your service into a Foreground service. After Android Oreo, you need to declare your background service a foreground service and have a visible notification while app is in background.

Read some more in: https://developer.android.com/guide/components/services