Can I listen to Eddystone beacons when my application is down?

With Google's new standard, Eddystone, they will provide Android support on Google Play services next to Api . Can we register for beacons with eddystone and get our application, even if the application does not work?

+2
source share
3 answers

Yes, this can be done with the Android Beacon Library , which fully supports Eddystone .

The background launch mechanism of your application works similarly with Eddystone, as well as for other types of beacons supported by the library. You are using a RegionBootstrap object in a custom Application class. You can read more about how this works here .

The only difference from Eddystone is that you need to configure the BeaconParser , which decodes the Eddystone-UID frame, and then set the Region to match the Eddystone namespace identifier:

 public class MyApplicationName extends Application implements BootstrapNotifier { private static final String TAG = ".MyApplicationName"; private RegionBootstrap regionBootstrap; @Override public void onCreate() { super.onCreate(); Log.d(TAG, "App started up"); BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this); // Detect the main identifier (UID) frame: beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19")); // wake up the app when a beacon matching myEddystoneNamespaceId is seen myEddystoneNamespaceId = Identifier.parse("0x2f234454f4911ba9ffa6"); Region region = new Region("com.example.myapp.boostrapRegion", myEddystoneNamespaceId, null, null); regionBootstrap = new RegionBootstrap(this, region); } @Override public void didDetermineStateForRegion(int arg0, Region arg1) { // Don't care } @Override public void didEnterRegion(Region arg0) { Log.d(TAG, "Got a didEnterRegion call"); // This call to disable will make it so the activity below only gets launched the first time a beacon is seen (until the next time the app is launched) // if you want the Activity to launch every single time beacons come into view, remove this call. regionBootstrap.disable(); Intent intent = new Intent(this, MainActivity.class); // IMPORTANT: in the AndroidManifest.xml definition of this activity, you must set android:launchMode="singleInstance" or you will get two instances // created when a user launches the activity manually and it gets launched from here. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(intent); } @Override public void didExitRegion(Region arg0) { // Don't care } } 
+5
source

Good, so it was very painful, but I managed to detect the beacons using the supported message API .

  • First create a Google Developer Console project
  • Enable the "Supported Messages API" for the newly created project.
  • Create an API key for this project as described here and add it to the manifest
  • Set up and register your beacons as described here ; I needed to install the Android application, open it, select the project that I just created, detect the beacon and register it using my application.
  • You will need to attach a message to your lighthouse for it to be detected. I did this using the Beacon Tools app , click on the registered beacon and tap "Attachments"
  • Now you can follow the sample code here and it should detect your beacon

     Nearby.Messages.subscribe(googleApiClient, new MessageListener() { @Override public void onFound(Message message) { Log.i(TAG, "Found : " + message); } @Override public void onLost(Message message) { Log.i(TAG, "Lost : " + message); } }, new SubscribeOptions.Builder() .setStrategy(Strategy.BLE_ONLY) .build()); 
+1
source

This was made possible after the release of the Google Play Services v8.4 SDK (December 2015).

See the following link: http://android-developers.blogspot.com/2015/12/google-play-services-84-sdk-is-available_18.html

0
source

All Articles