0

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

1 に答える 1

1

最も可能性の高い問題は、ビーコン スキャン サービスを宣言するための適切な AndroidManifest.xml エントリがアプリにないことです。これは通常、ライブラリのマニフェストからのマニフェストのマージを使用して自動的に行われます。Eclipse を使用している場合は、ライブラリのクイック スタート ガイドで説明されているように、マニフェストのマージをオンにする必要があります。

project.properties ファイルを編集して、次の行を追加します。manifestmerger.enabled=true

これが問題かどうかを判断する簡単な方法は、メソッドの先頭にログ行を追加することonBeaconServiceConnect()です。呼び出されていない場合は、サービスを開始できないことを意味します。

于 2014-11-18T12:16:31.797 に答える