我使用的是参考,http://altbeacon.github.io/android-beacon-library/samples.html。我也用How to detect Region Enter/Exit for multiple beacons using AltBeacon android-beacon-library?如何让AltBeacon库的BootstrapRegion识别iBeacon布局?
我试图在使用AltBeacon的Android信标库的背景中检测iBeacons。我包含了我的项目中的以下代码片段。到目前为止,我没有检测到在后台ibeacons ...任何帮助表示赞赏
我使用BeaconManager到
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
但是,我没有错误,没有信标检测。在Samsung Galaxy 4设备上运行应用程序调试时,应用程序将启动,但不会检测活动信标。我的信标是配置为iBeacons的Rad Beacons。 Rad Beacon应用程序检测到它们,我的其他AltBeacon库应用程序在前台运行,并检测到我的iBeacons。这些应用程序在三星Galaxy 4上运行。
我为背景信号检测设置的应用程序...未检测到iBeacons。
这是我的代码。对Constants.java的引用只是我的应用程序的一个常量文件。
package com.myApp.BTleDemo;
import android.app.Application;
import android.content.Intent;
import android.util.Log;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.altbeacon.beacon.startup.BootstrapNotifier;
import org.altbeacon.beacon.startup.RegionBootstrap;
import org.altbeacon.beacon.Region;
import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.RangeNotifier;
import org.altbeacon.beacon.Region;
import org.altbeacon.beacon.Identifier;
public class BackgroundMode extends Application implements BootstrapNotifier{
private static final String TAG = ".BackgroundMode";
private RegionBootstrap regionBootstrap;
private BeaconManager beaconManager;
SharedPreferences prefs;
List<Region> regions;
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
beaconManager = BeaconManager.getInstanceForApplication(this);
// Add AltBeacons Parser for iBeacon
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
// wake up the app when any beacon is seen (you can specify specific id filers in the parameters below)
Region region = new Region("com.myApp.BTleDemo.boostrapRegion", Identifier.parse(Constants.BT_UUID),
Identifier.fromInt(Constants.BT_MAJOR), Identifier.fromInt(Constants.BT_MINOR));
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
}
/*
@Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
Log.i(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");
}
}
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
} catch (RemoteException e) { }
}
}
*/
}
我没有收到任何ibeacon检测。没有发布预期的LogCat清单。我错过了一些步骤?
如果你在前台运行应用程序,你会得到检测结果吗?你在用什么IDE?如果使用Eclipse,是否可以验证在project.properties中启用了清单合并? – davidgyoung 2014-09-01 17:18:26
@davidgyoung我没有在前景或背景中获取信标检测。我正在使用Eclipse。在project.properties中自动生成文本文件列表target = android-18 android.library.reference.1 = ../../android-beacon-library – user3337849 2014-09-02 13:09:10
你有另一个设备可以测试吗?我之前在三星设备上使用iBeacon时遇到过问题(GT-N7105,GT-N7505都有我的Nexus没有的问题)。 – 2014-09-02 15:23:58