当前位置: 首页 > 知识库问答 >
问题:

未能检测到信标

耿珂
2023-03-14

使用https://altbeacon.github.io/android-beacon-library/samples.html中的代码试图检测IBeacon发射器,该发射器是iOS8,如下http://blog.passkit.com/configure-iphone-ibeacon-transmiter/,在哪一步出错了,我需要在区域中使用BeaconIdentifier作为mymonitoringuniqueid吗?无法检测到iBeacon....从ios监听IBeacon是否需要额外的步骤,因为使用的lib是Android Beacon库

还添加了

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) {    }
    }

}

仍未显示didEnterRegion编辑文件日志的日志消息:

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只在应用程序启动时激发一次如何使它只在应用程序关闭时停止listinig有人能指出如何做到这一点吗?

    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(标签,“I just seaked a beacon for the first fird!id1->”+region.getid1()+“id 2:”+region.getid2()+“id 3:”+region.getid3());设备出现,距离现在工作正常...

共有1个答案

江德海
2023-03-14

你开始做广告很重要。把对我有效的这个叫做。

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);
    }
 类似资料:
  • 日安。 我试着让我的电脑检测我的JDK,我想安装SDK管理器,对于eclipse,我的目标是运行一个虚拟的android设备。我已经安装了JDK,并设置了JAVA_HOME路径。下面是路径的一些片段。我目前正在运行Windows1064bit,没有找到任何链接到其他要做的事情。我已经找了一段时间了。 CMD错误消息 如果有人知道我做错了什么,请告诉我。

  • 我是一名Java新手,我想通过在minecraft上修改来进行训练。我在youtube上关注tutos(因为找不到新的tutos,所以是旧的tutos),安装了MCP,运行了一些命令(其中一些命令会让我出错),当我最终启动ta代码时,我注意到所有与forge库相关的方法和内容都是红色的。我不能用任何符号来解决这个问题。所以,请问有没有人有一个解决方案,我在网上搜索了很多次,但我发现它的旧芭蕾舞团不

  • 我一直试图让flutter检测Android SDK。 回报 PS I:\project\flutter\fluttertest\flutterproject>flutter doctor-v [√]flutter(Channel beta,v0.1.5,在Microsoft Windows上[Version 10.0.16299.248],locale en-美国) •flutter Versi

  • 我是SonarQube开发者的忠实粉丝。虽然这一次我需要做管理工作,因为我需要从一个新的安装配置它。我在SonarQube“Methods should not have too lanes”中看到了这个规则,但我没有看到它属于任何默认配置文件(“findbugs+fb-contrib”、“Sonar way”)。我想这就是我在任何项目中都没有看到任何这种类型的规则违反的原因。我认为这应该是一个常

  • 我正在尝试运行使用硒IDE记录的测试。以下网页由 IDE 生成 当我运行测试/执行命令,我得到一个错误说 有什么办法可以解决这个问题吗?

  • 本文向大家介绍Modernizr检测到的功能,包括了Modernizr检测到的功能的使用技巧和注意事项,需要的朋友参考一下 以下是Modernizr可以检测到的功能列表- 特征 CSS属性 JavaScript检查 @ font-face .fontface Modernizr.fontface 帆布 。帆布 现代画布 画布文字 .canvastext Modernizr.canvastext H