Skip to content

Commit

Permalink
Updated documentation with Monitoring after restart
Browse files Browse the repository at this point in the history
  • Loading branch information
Poberro committed Mar 18, 2016
1 parent 39e9801 commit 8211be0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changelog
- Added value validation for each setting
- Added RSSI read from connected beacon (for Proximity & Location beacons)
- Fixed enabling Secure UUID
- Fixed (https://github.com/Estimote/Android-SDK/issues/144): Wrong scan period while ranging/monitoring.
- Fixed (https://github.com/Estimote/Android-SDK/issues/144): stopRanging does not seem to stop actual ranging
- Fixed duplicated listener notification while ranging/monitoring
- Fixed rare crash on closing bluetooth gatt
- Fixed triggering scan cycle in Doze mode (Android 6.0+)
Expand Down
71 changes: 71 additions & 0 deletions DOC_monitoring_after_restart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Monitoring after system restart #

In order to have monitoring working after device is rebooted you must:
* Create empty broadcast receiver (Android will invoke Application.onCreate before BroadcastReceiver.onReceive):
```java
public class SystemBootReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
}
}
```
* In AndroidManifest.xml register that receiver to boot event (and optionally power events):
```xml
<receiver android:name=".SystemBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>
```
* Add a permission to start at boot.
```xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
```
* Create you own application class (if you don't have any) and start monitoring there (in onCreate method):
```java
public class MyApp extends Application {

private Region monitoringRegion = new Region("region", UUID.fromString("my-UUID"), 1, 1);
private BeaconManager beaconManager;
private NotificationManager notificationManager;

@Override public void onCreate() {
super.onCreate();
beaconManager = new BeaconManager(this.getApplicationContext());
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override public void onServiceReady() {
startMonitoring();
}
});
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}

private void startMonitoring() {
beaconManager.setMonitoringListener(new BeaconManager.MonitoringListener() {
@Override public void onEnteredRegion(Region region, List<Beacon> list) {
// invoke your action here
}

@Override public void onExitedRegion(Region region) {
// invoke your action here
}
});
beaconManager.startMonitoring(monitoringRegion);
}
}
```
* Don't forget to add you Application class to AndroidManifest.xml in <application> tag.
```xml
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:name=".MyApp"
>
```
* In one of your activities check permission for Bluetooth and Location. Access must be granted by the user before system is rebooted. If not monitoring will not start.
```java
SystemRequirementsChecker.checkWithDefaultDialogs(this);
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ In addition, we suggest you to check our guides for using **Location Beacons** a
- [Beacon connection](/DOC_deviceConnection.md)
- [Multiple advertisers in Location Beacons](/DOC_multiadvertisers.md)
- [Using telemetry packets](/DOC_telemetry.md)
- [Monitoring after system restart](/DOC_monitoring_after_restart.md)


### Quick start for nearables discovery
Expand Down

0 comments on commit 8211be0

Please sign in to comment.