簡體   English   中英

AltBeacon在Android上掃描iBeacon

[英]AltBeacon scanning iBeacon on Android

我想從Android手機Nexus5掃描iBeacon UUID =“ 2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6”

我遵循了AltBeacon和SO query的 示例 但是看不到掃描的東西。 我哪里錯了?

這是代碼

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();
    }
}

最可能的問題是您的應用程序沒有正確的AndroidManifest.xml條目來聲明信標掃描服務。 通常,這是使用庫清單中的清單合並自動完成的。 如果您使用的是Eclipse,則需要按照庫的“ 快速入門”指南中的說明打開清單合並:

編輯您的project.properties文件並添加以下行: manifestmerger.enabled=true

判斷這是否是問題的一種簡單方法是在onBeaconServiceConnect()方法的頂部添加一條日志行。 如果沒有被調用,則意味着該服務無法啟動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM