如何使用iBeacon-Android测试后台扫描并在后台启动应用程序?

时间:2014-03-13 02:58:40

标签: ibeacon ibeacon-android

我正在使用专业图书馆 但我刚发现doc for free library 我找不到专业版的任何文档。

另外,即使使用专业样本,我也不知道如何实现后台模式。

以下是步骤:

  1. 构建专业样本项目
  2. 启动iBeacon源(使用iPad)并可以检测到
  3. 启动应用程序,然后按home键进入 背景
  4. 关闭iBeacon来源
  5. 开启iBeacon来源
  6. 但是,超过5分钟,应用程序无法启动
  7. 那么,任何人都可以验证我所做的步骤吗? 如何更轻松地测试背景模式?

    另外,对于BootstrapNotifier,它只是在设备重启时才第一次工作吗? 之后,即使我将应用程序放在后台,应用程序也会在检测到iBeacon时启动?

1 个答案:

答案 0 :(得分:1)

您的测试方法听起来不错。我认为问题是专业版库的参考应用程序仅在启动后的第一次检测时自动启动应用程序。之后,它会发送通知,然后点击该通知启动应用。

这纯粹是出于演示目的。如果您愿意,可以在每次检测时将其更改为自动启动。只需更改此代码中的haveDetectedIBeaconsSinceBoot逻辑:

@Override
public void didEnterRegion(Region arg0) {
    // In this example, this class sends a notification to the user whenever an iBeacon
    // matching a Region (defined above) are first seen.
    Log.d(TAG, "did enter region.");
    if (!haveDetectedIBeaconsSinceBoot) {
        Log.d(TAG, "auto launching MainActivity");

        // The very first time since boot that we detect an iBeacon, we launch the
        // MainActivity
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // Important:  make sure to add android:launchMode="singleInstance" in the manifest
        // to keep multiple copies of this activity from getting created if the user has
        // already manually launched the app.
        this.startActivity(intent);
        haveDetectedIBeaconsSinceBoot = true;
    } else {
        // If we have already seen iBeacons and launched the MainActivity before, we simply
        // send a notification to the user on subsequent detections.
        Log.d(TAG, "Sending notification.");
        sendNotification();
    }


}

发布此问题时,main documentation page中缺少javadoc链接。现在已经解决了。

相关问题