我已经使用了基本的样本由 Altbeacon
规定(无线网络
)的GitHub库的应用程序。
I have used the basic sample application provided by Altbeacon
(Radio Network
) on the Github repo.
一切似乎都在为我的iBeacon直接从监控
到测距
但只有在前景
Everything seems to work for my iBeacon right from Monitoring
to the Ranging
but only in Foreground
我所做的这些下面的步骤来获得它在前台工作。
I have done these following steps to get it working in Foreground.
public class BeaconReferenceApplication extends Application implements BootstrapNotifier, RangeNotifier
{
private static final String TAG = "BeaconReferenceApplication";
private BeaconManager mBeaconManager;
private Region mAllBeaconsRegion;
private BackgroundPowerSaver mBackgroundPowerSaver;
private RegionBootstrap mRegionBootstrap;
private BackgroundPowerSaver backgroundPowerSaver;
@Override
public void onCreate()
{
mAllBeaconsRegion = new Region(getPackageName(), null, null, null);
mBeaconManager = BeaconManager.getInstanceForApplication(this);
mBackgroundPowerSaver = new BackgroundPowerSaver(this);
mRegionBootstrap = new RegionBootstrap(this, mAllBeaconsRegion);
mBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
backgroundPowerSaver = new BackgroundPowerSaver(this);
}
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> arg0, Region arg1)
{
System.out.println("app-> didRangeBeaconsInRegion");
}
@Override
public void didDetermineStateForRegion(int arg0, Region arg1)
{
System.out.println("app-> didDetermineStateForRegion");
}
@Override
public void didEnterRegion(Region arg0)
{
System.out.println("app-> didEnterRegion");
try
{
Log.d(TAG, "entered region. starting ranging");
mBeaconManager.setRangeNotifier(this);
mBeaconManager.startRangingBeaconsInRegion(mAllBeaconsRegion);
}
catch(RemoteException e)
{
Log.e(TAG, "Cannot start ranging");
}
Intent intentMainActivity = new Intent(this,MonitoringAndRangingActivity.class);
intentMainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentMainActivity);
}
@Override
public void didExitRegion(Region arg0)
{
System.out.println("app-> didExitRegion");
}
public void setMonitoringAndRangingActivity(MonitoringAndRangingActivity activity)
{
mBeaconManager.setBackgroundMode((activity==null)?true:false);
}
}
编辑:
我添加的方法 mBeaconManager.setBackgroundMode(真);
,但没有任何帮助,我只是得到从 BlutoothAdapter
的stopLE扫描()消息,一切都停止,我需要的服务或别的什么来实现呢?
I have added the method
mBeaconManager.setBackgroundMode(true);
but no help, i just get the stopLE scan() message from BlutoothAdapter
and everything stops, do i need to implement this in a Service or anything else?
但只要我去后台(pressing回或家庭)的日志和回调方法
停止响应。
这有什么,我很想念激活背景iBeacon检测。
But as soon as I go to background(pressing back or home) the logs and the callback methods
stop responding.
Is there anything that i am missing to activate the background iBeacon detection.
任何投入就如同一个福音。
Any inputs would be like a boon.
在 BackgroundPowerSaver
它会自动转换了Android灯塔图书馆为背景模式。有没有需要调用 setBackgroundMode
手动。
If you are using the BackgroundPowerSaver
it will transition the Android Beacon Library into background mode automatically. There is no need to call setBackgroundMode
manually.
在该库在后台模式下,它只是做了扫描,每5分钟,以节省功率(这个时间是可以配置的),所以它可能需要长达五分钟检测一盏明灯。我会看LogCat中五分钟,而你的ASPP是在后台,看看你在任何时间检测。如果没有,添加LogCat中摘录到你的问题将是有益的。
When the library is in background mode, it only does a scan every 5 minutes to save power (this timing is configurable) so it may take up to five minutes to detect a beacon. I would watch LogCat for five minutes while your aspp is in the background and see if you get any detections in that time. If not, adding a LogCat excerpt to your question would be helpful.