Estimote / Android-Proximity-SDK

Estimote Proximity SDK for Android
https://developer.estimote.com
MIT License
82 stars 42 forks source link

Restore foreground service after reboot #31

Open MBach opened 6 years ago

MBach commented 6 years ago

Prerequisites

Basic information

Estimote SDK version: 0.3.3

Android devices affected: Samsung Galaxy S7

Android OS version affected: all

Beacon hardware version: F3.3

Description

As I already have when I monitor Geofence areas, I need to have the same behavior for Beacons.

Steps to reproduce:

  1. Register background scan service with Foreground Service
  2. Reboot your phone
  3. No more background scan

Expected behavior: The background scan is restored after booting up.

Additional information

As stated in the official guidelines, "silent bluetooth scan" is not allowed. But if you create a class that extends BroadcastReceiver, it might be possible to restore the previously created persistent notification. By doing so, it doesn't seem to be in contradiction with the guidelines.

Can I do by myself with latest SDK? I think it's a little different than the use case described with ProximityTrigger for Android 8.0 Oreo. I don't want to trigger when the app is killed, I "just" want the service to be reactivated.

pawelDylag commented 6 years ago

Hey @MBach

ProximityTrigger is wrapping the ugly Android API for launching the scan with your PendingIntent instead of a callback object. There are two options to use ProximityTrigger in our SDK:

  1. A ready-made displayNotificationWhenInProximity(notification: Notification) that registers a broadcast receiver under the hood. When a pending intent gets triggered by the scan, the BR will display the given notification.
  2. triggerPendingIntentWhenInProximity(pendingIntent: PendingIntent) which let's you manually create pending intent and control it.

The problem with scanning after rebooting is that the registered startScan callbacks/pendingIntents (through Android API) are flushed, so you won't get any results back afterwards, so your BR won't be triggered.

The one idea is to register a BR for the boot events and then launch our ProximityTrigger there. Unfortunately, from my experience it's impossible to call startScan(...) from the background successfully. You need to have your app in the foreground.

Second solution is to register a BR for boot events and then launch our ProximityObserver in the foreground service there. But I need to validate if this is possible, cause I'm not 100% sure.

I can't look deeper in this case right now, because I want to keep up with our sprint schedule. I will add this to my backlog anyway :)

Regards, Paweł

MBach commented 6 years ago

Ok thanks for your response. Currently, I also don't have the time to implement my own Broadcast Receiver, but I'll try in the next weeks.

MBach commented 6 years ago

Hi @pawelDylag, Do you have some new informations on this question?

riziqHabib commented 5 years ago

me too facing the same issue....is there any solution?