首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AltBeacon

使用AltBeacon
EN

Stack Overflow用户
提问于 2014-09-29 15:57:02
回答 1查看 1.1K关注 0票数 1

我想使用AltBeacon库来检测来自Radius Networks的RadBeacon标记。为了理解这个库是如何工作的,我想使用AltBeacon的参考应用程序。

我在我的示例应用程序中实现了this code。在将AltBeacon库添加到项目中之后,我就可以运行项目了。

就像我之前提到的,我喜欢检测Radius Networks的IBeacons RadBeacon标签。我知道我需要使用BeaconParser。我的问题是RadBeacon标签的BeaconParser是什么样子的。Here是一个用于估计信标的IBeacon解析器。

当我调试这个项目并查看logcat内部时,我可以看到以下消息:

代码语言:javascript
复制
"Beacon detected: id1: "UUID of RadBeacon" id2= "Major of RadBeacon" id3:"Minor of RadBeacon"".
"looking for ranging region mathes for this beacon"
"got record"
"This is not a matching Beacon advertisment."

如何更改BeaconParser?这是我的源代码

代码语言:javascript
复制
public class FindRadBeaconActivity extends ActionBarActivity implements BeaconConsumer{
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
protected static final String TAG = "RangingActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_find_rad_beacon);

    // check bluetooth
    verifyBluetooth();

    beaconManager.getBeaconParsers().add(new BeaconParser().
            setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
    beaconManager.debug = true;
    beaconManager.bind(this);

}

@Override 
protected void onDestroy() {
    super.onDestroy();
    beaconManager.unbind(this);
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.find_rad_beacon, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onBeaconServiceConnect() {
    beaconManager.setMonitorNotifier(new MonitorNotifier() {
    @Override
    public void didEnterRegion(Region region) {
      Log.i(TAG, "I just saw an beacon for the first time!");       
    }

    @Override
    public void didExitRegion(Region region) {
      Log.i(TAG, "I no longer see an beacon");
    }

    @Override
    public void didDetermineStateForRegion(int state, Region region) {
        Log.i(TAG, "I have just switched from seeing/not seeing beacons: "+state);      
    }
    });

    try {
        beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
    } catch (RemoteException e) {   }
}

private void verifyBluetooth() {

    try {
        if (!BeaconManager.getInstanceForApplication(this).checkAvailability()) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Bluetooth not enabled");          
            builder.setMessage("Please enable bluetooth in settings and restart this application.");
            builder.setPositiveButton(android.R.string.ok, null);
            builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    finish();
                    System.exit(0);                 
                }                   
            });
            builder.show();
        }           
    }
    catch (RuntimeException e) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Bluetooth LE not available");         
        builder.setMessage("Sorry, this device does not support Bluetooth LE.");
        builder.setPositiveButton(android.R.string.ok, null);
        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                finish();
                System.exit(0);                 
            }

        });
        builder.show();

    }

}

}

EN

回答 1

Stack Overflow用户

发布于 2014-10-30 18:46:18

如果您正在寻找RadBeacon布局,请使用以下布局

代码语言:javascript
复制
mBeaconManager
            .getBeaconParsers()
            .add(new BeaconParser()
                    .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26095062

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档