Glen Zheng
Glen Zheng

Reputation: 1

How to wake up the app with Eddystone in Android

I want to wake up my app with Eddystone, however nothing happened when my phone get close to the signal of Eddystone. I did it with Android Beacon library. And it is as blew:

    `
onCreate(){
    mBeaconManager = BeaconManager.getInstanceForApplication(this);
    // Detect the main Eddystone-UID frame:
    mBeaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));
    mBeaconManager.setBackgroundBetweenScanPeriod(50);
    mBeaconManager.setBackgroundScanPeriod(50);
    mBeaconManager.setForegroundBetweenScanPeriod(50);
    mBeaconManager.setForegroundScanPeriod(50);
    mBeaconManager.setBackgroundBetweenScanPeriod(50);
    mBeaconManager.setForegroundScanPeriod(50);
    mBeaconManager.applySettings();
    mBeaconManager.bind(this);

}`

Android.xml:

<application 
    android:name="com.example.MyApplicationName"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <!-- Note:  the singleInstance below is important to keep two copies of your activity from getting launched on automatic startup -->
    <activity
        android:launchMode="singleInstance"  
        android:name="com.example.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
    <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Is there anyone did it before, please help me with it. Thanks

Upvotes: 0

Views: 1292

Answers (1)

davidgyoung
davidgyoung

Reputation: 64941

Yes, it is possible to wake up an app with Eddystone-UID using the Android Beacon Library. It works the same way as with AltBeacon or iBeacon.

The easiest way to get this to happen is to start with the reference app here:

https://github.com/altbeacon/android-beacon-library-reference

The only modification you need to make is to add the beacon parser for Eddystone-UID:

mBeaconManager.getBeaconParsers().add(new BeaconParser().
        setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));

Looking at the code in the question, setting the scan periods to 50 is going to be a problem, as 50ms is not long enough to reliably detect a beacon. I would remove these custom scan period configurations and use the defaults.

A few tips:

  1. Make sure you can detect beacons in the foreground before trying to make your app work in the background.
  2. Make sure your app is using RegionBootstrap as in the reference app as described in the "Starting an App in the Background" section here
  3. When testing background detection, make sure you are out of region before starting the test. To do this, bring your app to the foreground, and have your beacon(s) turned off for 30 seconds. This will ensure you are out of region. Always to this before starting a background detection test.
  4. If you kill your app from the task switcher, wait 5 minutes to ensure it is restarted in the background before starting your testing.
  5. Be realistic about how long it might take to detect a beacon in the background. Read here for more info.

Upvotes: 1

Related Questions