简体   繁体   English

AltBeacon在Android上扫描iBeacon

[英]AltBeacon scanning iBeacon on Android

I want to scan an iBeacon UUID = "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6" from Android phone Nexus5 我想从Android手机Nexus5扫描iBeacon UUID =“ 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6”

I have followed example from AltBeacon and SO query . 我遵循了AltBeacon和SO query的 示例 But don't see anything scanning. 但是看不到扫描的东西。 Where am I wrong? 我哪里错了?

Here is the code 这是代码

private static final String TAG = "ALTBEACON";
private BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
private String UUID = "2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6";
private static final int REQUEST_ENABLE_BT = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if(beaconManager.checkAvailability()){
        beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
        beaconManager.bind(this);
    }
    else{
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // User chose not to enable Bluetooth.
    if (requestCode == REQUEST_ENABLE_BT && resultCode == Activity.RESULT_CANCELED) {
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}


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


@Override
public void onBeaconServiceConnect() {
    beaconManager.setMonitorNotifier(new MonitorNotifier() {

        @Override
        public void didExitRegion(Region region) {
            Log.i(TAG, "Exit from Region");
            Toast.makeText(getApplicationContext(), "Exit from Region", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void didEnterRegion(Region region) {
            Log.i(TAG, "Entered in Region");
            Toast.makeText(getApplicationContext(), "Entered in Region", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void didDetermineStateForRegion(int state, Region region) {
            Log.i(TAG, "Not Sure... State : "+state+" ... Region : "+region.describeContents());
            Toast.makeText(getApplicationContext(), "Not Sure... State : "+state+" ... Region : "+region.describeContents(), Toast.LENGTH_SHORT).show();
        }
    });

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

The most likely problem is that your app does not have the proper AndroidManifest.xml entries to declare the beacon scanning service. 最可能的问题是您的应用程序没有正确的AndroidManifest.xml条目来声明信标扫描服务。 This is generally done automatically using manifest merging from the library's manifest. 通常,这是使用库清单中的清单合并自动完成的。 If you are using Eclipse, you need to turn on manifest merging as described in the library's Quick Start guide : 如果您使用的是Eclipse,则需要按照库的“ 快速入门”指南中的说明打开清单合并:

Edit your project.properties file and add the line: manifestmerger.enabled=true 编辑您的project.properties文件并添加以下行: manifestmerger.enabled=true

An easy way to tell if this is the problem is to add a log line to the top of your onBeaconServiceConnect() method. 判断这是否是问题的一种简单方法是在onBeaconServiceConnect()方法的顶部添加一条日志行。 If it is not getting called, that means the service cannot start up. 如果没有被调用,则意味着该服务无法启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM