你的测试方法听起来不错。我认为问题在于专业库的参考应用程序仅在启动后第一次检测时自动启动应用程序。之后,它会发送通知,然后点击该通知启动应用程序。
这纯粹是为了演示目的。如果您愿意,您可以将其更改为在每次检测时自动启动。只需更改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();
}
}
当您发布此问题时,主文档页面中缺少 javadoc 链接。现在已经解决了。