Can you use the EstimoteTelemetry class in the background?
I would like to receive a notification when the beacon is moving and the app is closed.
Do you have a solution?
Hi @DColonna82,
according to the Estimote Android SDK, the Eddystone-TLM packet discovery is a foreground feature.
So I can not use the Estimote Telemetry class in the background! Are there alternative solutions?
Discovery should work in the background as well, it’s just currently optimized for the foreground usage & maximum responsiveness.
For background usage, it’s best to put it in your Application subclass instead of an Activity, as activities can be suspended/deallocated when your app is in the background.
Hi @heypiotr,
is it also possible to use a service for background packet discovery?
Hi guys, this is my code! I think monitoring does not work properly while the telemetry works fine. Do you have suggestions for a proper functioning of Monitoring and Telemetry together in a class that extends Application?
public class Telemetry_Monitoring extends Application
{
private BeaconManager beaconManager;
private String scanId;
Region mRegionBlueberry = new Region("monitored region", UUID.fromString("xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"),xxxxx, xxxxx);
Region mRegionMint = new Region("monitored region", UUID.fromString("xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"),xxxxx, xxxxx);
Region mRegionMarshmallow = new Region("monitored region", UUID.fromString("xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx"),xxxxx, xxxxx);
@Override
public void onCreate()
{
beaconManager = new BeaconManager(getApplicationContext());
beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener()
{
@Override
public void onEnteredRegion(Region region, List<Beacon> list)
{
if(region.getMajor()==xxxxx)
showNotification("Bluebarry range","Bluebarry beacon!");
if(region.getMajor()==xxxxx)
showNotification("Mint range","Mint beacon!");
if(region.getMajor()==xxxxx)
{
showNotification("Marshmallow range","Marshmallow beacon!");
}
}
@Override
public void onExitedRegion(Region region) { }
});
beaconManager.setTelemetryListener(new BeaconManager.TelemetryListener()
{
@Override
public void onTelemetriesFound(List<EstimoteTelemetry> telemetries)
{
for (EstimoteTelemetry tlm : telemetries)
{
if(tlm.motionState)
{
if(tlm.deviceId.toHexString().equals("xxxxxxxxxxxxxxxxxxxxxxxxxxx"))
showNotification("BLUEBERRY BEACON", "Motion detected! ");
if(tlm.deviceId.toHexString().equals("xxxxxxxxxxxxxxxxxxxxxxxxxxx"))
showNotification("MINT BEACON", "Motion detected! ");
if(tlm.deviceId.toHexString().equals("xxxxxxxxxxxxxxxxxxxxxxxxxxx"))
showNotification("MARSHMALLOW BEACON", "Motion detected! ");
}
}
}
});
beaconManager.connect(new BeaconManager.ServiceReadyCallback()
{
@Override
public void onServiceReady()
{
//Beacon Bluebarry
beaconManager.startMonitoring(mRegionBlueberry);
//Beacon Mint
beaconManager.startMonitoring(mRegionMint);
//Beacon Marshmallow
beaconManager.startMonitoring(mRegionMarshmallow);
//Telemetry
scanId = beaconManager.startTelemetryDiscovery();
}
});
}
public void showNotification(String title, String message)
{
Intent notifyIntent = new Intent(this, MainActivity.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivities(this, 0,
new Intent[]{notifyIntent}, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification.Builder(this)
.setSmallIcon(android.R.drawable.ic_dialog_info)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
notification.defaults |= Notification.DEFAULT_SOUND;
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, notification);
}
}
Hey,
why do you think it doesn’t work? Not notifying at all?
I receive Monitoring Notifications with a lower frequency. it’s normal?
Yeah, because there is a 30 time-guard with the monitoring technology.