未能检测到信标

问题描述 投票:0回答:1

使用下面的代码 https:/altbeacon.github.ioandroid-beacon-librarysamples.html。 试图检测ios 8的IBeacon发射器,如下所示。http:/blog.passkit.comconfigure-iphone-ibeacon-transmitter。 我有点不明白是哪一步出了问题,我需要在Region中使用BeaconIdentifier作为我的MonitoringUniqueId吗? 无法检测到IBeacon......我是否需要一个额外的步骤来监听ios中的IBeacon,因为使用的lib是Android Beacon库。

又加

beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"))。

如同 这是用AltBeacon的Android Beacon库检测iBeacons的正确布局吗?

BeaconIdentifier = @"com.example.apple-samplecode.AirLocate"。

import android.app.Activity;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import android.widget.TextView;

import org.altbeacon.beacon.BeaconConsumer;
import org.altbeacon.beacon.BeaconManager;
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.MonitorNotifier;
import org.altbeacon.beacon.Region;
import org.altbeacon.beacon.logging.LogManager;


public class MainActivity extends Activity implements BeaconConsumer{

    protected static final String TAG = "MonitoringActivity";
    private BeaconManager beaconManager;
    private TextView message;
    private TextView num;
    private int IBeaconCount;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        message = (TextView)findViewById(R.id.IBeaconMsg);
        num = (TextView)findViewById(R.id.Numdetect);
        beaconManager = BeaconManager.getInstanceForApplication(this);
        /*
        *  beaconManager.getBeaconParsers().add(new BeaconParser().
               setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
        * */
        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);
        //Hz to see if its receiveing from the emitter
        //beaconManager.setForegroundScanPeriod(2000l);
        //beaconManager.setBackgroundBetweenScanPeriod(1100l);
        //

        //IBeaconCount = 0;
        //num.setText(IBeaconCount);
    }

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

    @Override
    protected void onResume() {
        super.onResume();
        //num.setText(IBeaconCount);
    }

    @Override
    public void onBeaconServiceConnect() {
        beaconManager.setMonitorNotifier(new MonitorNotifier() {
            @Override
            public void didEnterRegion(Region region) {
                //IBeaconCount++;
                Log.i(TAG, "I just saw an beacon for the first time!");
                message.setText("I just saw an beacon for the first time!");
                LogManager.d(TAG, "didEnterRegion %s", region);

            }

            @Override
            public void didExitRegion(Region region) {
                Log.i(TAG, "I no longer see an beacon");
                message.setText("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);
                message.setText("I have just switched from seeing/not seeing beacons: "+state);
            }
        });

        try {
            //beaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
            beaconManager.startMonitoringBeaconsInRegion(new Region("com.example.apple-samplecode.AirLocate", null, null, null));
        } catch (RemoteException e) {    }
    }

}

仍然没有显示didEnterRegionEdited文件日志的消息。

04-08 12:45:39.283    7223-7223/com.mobinteg.ibeacon W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device.  Using default
04-08 12:45:39.283    7223-7223/com.mobinteg.ibeacon W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device.  Using default
04-08 12:45:39.303    7223-7223/com.mobinteg.ibeacon I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build:  ()
    OpenGL ES Shader Compiler Version: E031.24.00.08
    Build Date: 03/21/14 Fri
    Local Branch: AU200+patches_03212014
    Remote Branch:
    Local Patches:
    Reconstruct Branch:
04-08 12:45:39.343    7223-7223/com.mobinteg.ibeacon D/OpenGLRenderer﹕ Enabling debug mode 0
04-08 12:45:39.413    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:39.453    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:39.483    7223-7262/com.mobinteg.ibeacon I/System.out﹕ Thread-1162(HTTPLog):isShipBuild true
04-08 12:45:39.483    7223-7262/com.mobinteg.ibeacon I/System.out﹕ Thread-1162(HTTPLog):SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
04-08 12:45:39.523    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-45
04-08 12:45:39.573    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-80
04-08 12:45:40.123    7223-7262/com.mobinteg.ibeacon W/ModelSpecificDistanceCalculator﹕ Cannot find match for this device.  Using default
04-08 12:45:40.563    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:40.563    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:40.563    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:40.603    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-45
04-08 12:45:40.673    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-80
04-08 12:45:41.673    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:41.673    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:41.673    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:41.713    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-44
04-08 12:45:42.783    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:42.803    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:42.813    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:42.883    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-44
04-08 12:45:43.053    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-87
04-08 12:45:43.933    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-08 12:45:43.943    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-08 12:45:43.953    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-08 12:45:44.003    7223-7248/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=6A:7F:9C:42:A0:00 RSSI=-79
04-08 12:45:44.013    7223-7246/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=64:98:8D:4F:33:00 RSSI=-39
04-08 12:45:45.063    7223-7223/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()

在onBeaconServiceConnect里面添加了RangeNotifier,如下图所示,但它从来没有进入didRangeBeaconsInRegion和didEnterRegion,didExitRegion和didDetermineStateForRegion只有在应用程序启动时才发射一次,如何使它allslistinig只有在应用程序关闭时才停止,有人能指出如何做吗?

    beaconManager.setRangeNotifier(new RangeNotifier() {
        @Override
        public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
            Log.i(TAG,"beacons.size less then 0???????");
            if (beacons.size() > 0) {
                Log.i(TAG, "The first beacon I see is about " + beacons.iterator().next().getDistance() + " meters away.");
            }

            /*
            for(Beacon beacon: beacons){
                Log.i(TAG, "Beacon detected with id1: "+beacon.getId1()+" id2:"+beacon.getId2()+" id3: "+beacon.getId3()+" distance: "+beacon.getDistance());
            }
            */
        }


    });

日志文件。

04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Scan started
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Set scan periods called with 1100, 110 Background mode must have changed.
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ We are not in the background.  Cancelling wakeup alarm
04-09 12:28:16.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ cancel wakeup alarm: null
04-09 12:28:16.433  27850-27874/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=73:A5:A7:D6:24:06 RSSI=-67
04-09 12:28:16.433  27850-27874/com.mobinteg.ibeacon D/CycledLeScannerForJellyBeanMr2﹕ got record
04-09 12:28:16.443  27850-27872/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=D0:4F:7E:0A:88:5B RSSI=-92
04-09 12:28:16.443  27850-27872/com.mobinteg.ibeacon D/CycledLeScannerForJellyBeanMr2﹕ got record
04-09 12:28:16.443  27850-27891/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac.  The bytes I see are: 02011a0bff4c0009060102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:16.443  27850-27891/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting 02 15.  The bytes I see are: 02011a0bff4c0009060102000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac.  The bytes I see are: 02011a1aff4c00021513ba60dbdcdb42ec99a33f7eef7bbdbd00000000c50000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/BeaconParser﹕ This is a recognized beacon advertisement -- 02 15 seen
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/BeaconService﹕ beacon detected : id1: 13ba60db-dcdb-42ec-99a3-3f7eef7bbdbd id2: 0 id3: 0
04-09 12:28:16.443  27850-27890/com.mobinteg.ibeacon D/Callback﹕ attempting callback via intent: ComponentInfo{com.mobinteg.ibeacon/org.altbeacon.beacon.BeaconIntentProcessor}
04-09 12:28:16.453  27850-27890/com.mobinteg.ibeacon D/BeaconService﹕ looking for ranging region matches for this beacon
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon D/BeaconIntentProcessor﹕ got an intent to process
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon D/BeaconIntentProcessor﹕ got monitoring data
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon D/BeaconIntentProcessor﹕ Calling monitoring notifier: com.mobinteg.ibeacon.MainActivity$2@420d5b28
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon I/MonitoringActivity﹕ I have just switched from seeing/not seeing beacons: 1
04-09 12:28:16.453  27850-27892/com.mobinteg.ibeacon I/MonitoringActivity﹕ I just saw an beacon for the first time!
04-09 12:28:17.383  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 97 milliseconds
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Done with scan cycle
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ stopping bluetooth le scan
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/BluetoothAdapter﹕ stopLeScan()
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Normalizing between scan period from 110 to -1027
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ starting a new scan cycle
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ starting a new bluetooth le scan
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/BluetoothAdapter﹕ startLeScan(): null
04-09 12:28:17.493  27850-27872/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onClientRegistered() - status=0 clientIf=5
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 1100 milliseconds
04-09 12:28:17.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Scan started
04-09 12:28:17.503  27850-27874/com.mobinteg.ibeacon D/BluetoothAdapter﹕ onScanResult() - Device=73:A5:A7:D6:24:06 RSSI=-63
04-09 12:28:17.503  27850-27874/com.mobinteg.ibeacon D/CycledLeScannerForJellyBeanMr2﹕ got record
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconParser﹕ This is not a matching Beacon advertisement. (Was expecting be ac.  The bytes I see are: 02011a1aff4c00021513ba60dbdcdb42ec99a33f7eef7bbdbd00000000c50000000000000000000000000000000000000000000000000000000000000000
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconParser﹕ This is a recognized beacon advertisement -- 02 15 seen
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconService﹕ beacon detected multiple times in scan cycle : id1: 13ba60db-dcdb-42ec-99a3-3f7eef7bbdbd id2: 0 id3: 0
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconService﹕ beacon detected : id1: 13ba60db-dcdb-42ec-99a3-3f7eef7bbdbd id2: 0 id3: 0
04-09 12:28:17.503  27850-28015/com.mobinteg.ibeacon D/BeaconService﹕ looking for ranging region matches for this beacon
04-09 12:28:18.493  27850-27850/com.mobinteg.ibeacon D/CycledLeScanner﹕ Waiting to stop scan cycle for another 99 milliseconds

将didEnterRegion里面的日志改为了

Log.i(TAG, "I just saw an beacon for the first time! Id1->"+region.getId1());

并开始输入didRangeBeaconsInRegion,但beacons.size()显示为0......。

没问题 Log.i(TAG, "I just saw an beacon for the first time! Id1->"+region.getId1()+" id 2:"+region.getId2()+" id 3:"+region.getId3()); 设备出现了,现在距离工作正常......

android ibeacon ibeacon-android altbeacon android-ibeacon
1个回答
0
投票

这是重要的,你开始Advertizing.调用这个工作对我来说。

public void startEmitting() {
        Beacon beacon = new Beacon.Builder()
                .setId1("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6")
                .setId2("1")
                .setId3("2")
                .setManufacturer(0x0118)
                .setTxPower(-59)
                .setDataFields(Arrays.asList(new Long[]{0l}))
                .build();
        BeaconParser beaconParser = new BeaconParser()
                .setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
        BeaconTransmitter beaconTransmitter = new BeaconTransmitter(getApplicationContext(), beaconParser);
        beaconTransmitter.startAdvertising(beacon);
    }
© www.soinside.com 2019 - 2024. All rights reserved.