您的測試方法聽起來很好。我認爲問題是專業圖書館的參考應用程序僅在啓動後第一次檢測時自動啓動應用程序。之後,它會發送通知,然後點擊該通知啓動應用程序。
這純粹是爲了演示的目的。如果您願意,您可以將其更改爲在每次檢測時自動啓動。簡單地改變此代碼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鏈接從main documentation page丟失,當你張貼了這個問題。現在已經修復。
剛剛嘗試忽略hasDetectedIBeaconsSinceBoot的所有邏輯,無論如何只需startActivity,然後關閉源10-15秒後,再打開,可以啓動活動。 – jjLin
我已經更新了JavaDoc鏈接:http://developer.radiusnetworks.com/ibeacon/android/pro/javadocs/ – davidgyoung