我仍然使用Davidgyoung的帖子和这些评论,现在我有了一个FatalException:
E/AndroidRuntime:致命异常: IntentServiceBeaconIntentProcessor进程: databerries.beaconapp,PID: databerries.beaconapp.MyApplicationName.didEnterRegion(MyApplicationName.java:76) at org.altbeacon.beacon.BeaconIntentProcessor.onHandleIntent(BeaconIntentProcessor.java:83) at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java ):136)在android.os.HandlerThread.run(HandlerThread.java:61)
此错误是由于调用setRangeNotifier()而造成的?
-------EDIT--------
在发布了Davidgyoung的帖子和这些评论之后,我尝试了这种方法,但仍然没有用:
public class MyApplicationName extends Application implements BootstrapNotifier {
private static final String TAG = ".MyApplicationName";
private RegionBootstrap regionBootstrap;
private BeaconManager beaconManager;
List region_list = new ArrayList();
@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "App started up");
// wake up the app when any beacon is seen (you can specify specific id filers in the parameters below)
List region_list = myRegionList();
regionBootstrap = new RegionBootstrap(this, region_list);
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.setBackgroundScanPeriod(3000l);
beaconManager.setBackgroundBetweenScanPeriod(5000l);
}
@Override
public void didDetermineStateForRegion(int arg0, Region arg1) {
// Don't care
}
@Override
public void didEnterRegion(Region region) {
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, MyActivity.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);
String zone = region.toString();
Log.d(TAG, "Enter in region");
String text = "Enter in " + zone;
Log.d(TAG, text);
String uuid = "UUID : " + region.getId1();
Log.d(TAG, uuid);
//This part is not working
beaconManager.setRangeNotifier(this);
beaconManager.startRangingBeaconsInRegion(region);
}
@Override
public void didExitRegion(Region arg0) {
// Don't care
}
错误是关于setRangeNotifier
中的输入和startRangingBeaconsInRegion
的异常。
这不是我的主修课,我的主修课:
public class MyActivity extends Activity{
public final static String EXTRA_MESSAGE = "com.example.myapp.MESSAGE";
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("myActivity","onCreate");
}
}
我要区域内所有信标的in。如果我理解这种方法,当应用程序检测到一个区域时,它会在后台被唤醒,通常,"startRangingBeaconsInRegion“可以给我一个与此对应的信标列表,我可以获取Ids。
-------Original--------
我想知道我周围所有的灯塔。我知道这个信标的UUID,我可以通过'region.toString();‘获得它。但是,我需要其他信标的身份。而且,我在didRangeBeaconsInRegion上没有“灯塔”。
如何了解该地区的信标?
最后一个问题,有可能在后台说出来吗?
谢谢
发布于 2015-04-10 06:24:56
您可以在这里的“测距示例代码”一节中看到对信标进行测距的示例:http://altbeacon.github.io/android-beacon-library/samples.html
这将允许您通过查看回调中的Beacon
中返回的每个Collection<Beacon> beacons
对象来读取所有标识符。如下所示:
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
for (Beacon beacon: beacons) {
Log.i(TAG, "This beacon has identifiers:"+beacon.getId1()+", "+beacon.getId2()+", "+beacon.getId3());
}
}
一旦您开始测距,它将继续在后台这样做,前提是您不退出启动测距的活动。在库的某些用途下,范围在后台会减慢,但只有在使用BackgroundPowerSaver
类时才会发生这种情况。如果您不希望在后台范围内减速,只需在库中不启用后台电源节省。
https://stackoverflow.com/questions/29561927
复制相似问题