简体   繁体   English

无法使用“ altbeacon” libary android监视信标区域

[英]Failing to monitor beacon regions with “altbeacon” libary android

I am run callbacks for changes in the state of my region with the altbeacon libary . 我使用altbeacon libary运行回调以更改我所在地区的状态。 Sample code from here ("Starting an App in the Background" section) . 此处的示例代码(“在后台启动应用程序”部分) But after trying everything I can come up with, still no luck. 但是在尝试了所有我能想到的之后,仍然没有运气。 What am I missing? 我想念什么?

All im getting in my App is: 我进入我的应用程序的全部是:

  • RegionApp: App started up
  • RegionApp: Got a didDetermineStateForRegion call, isInRegion: false

Details: 细节:

  • Tried using the latest version of the libary org.altbeacon:android-beacon-library:2+ and an older one 'org.altbeacon:android-beacon-library:2.12.1' 使用最新版本的org.altbeacon:android-beacon-library:2+和较旧的'org.altbeacon:android-beacon-library:2.12.1'
  • 3 Kontakt.io Beacons with IBeacon protocol. 3具有IBeacon协议的Kontakt.io信标。 (firmware v4) (固件v4)
  • Attempted different beaconLayout , im quite sure this one is right. 尝试了不同的beaconLayout ,我很确定这是正确的。
  • Permissions are granted by going to app settings. 权限通过转到应用程序设置来授予。 Like this 像这样
  • compileSdkVersion: 28 编译标度:28

EDIT: With the ranging example code I can't see the beacons either. 编辑:用范围示例代码,我也看不到信标。 But with the Kontakt app I can. 但有了Kontakt应用程序,我可以。 One of the beacons according to BeaconScope : 根据BeaconScope的信标之一

f7826da6-4fa2-4e98-8024-bc5b71e0893e
id2: 29737
id3: 24354
power: -77 dBm
distance: 0.9 meters
rssi -65dBm
average rssi: -76.5 dBm
packets: 78
packes/sec: 1.4
detection rate: 100%
stabilized: true (sometimes false)
sample period: 53.9 secs

Attempted on 尝试开启

  • Nokia 6.1 / Android 9
  • Samsung Note 9 / Android 9
  • Huawei GRA-L09 / Android 6

Code: 码:

App.java

public class App extends Application implements BootstrapNotifier {
    private static final String TAG = "RegionApp";
    private RegionBootstrap regionBootstrap;

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "App started up");
        BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);

        beaconManager.getBeaconParsers().add(new BeaconParser().

        setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
        // Also tried this: m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25;

        Region region = new Region("com.example.regionmonitor.boostrapRegion", null, null, null);
        // Also tried creating region with defining UUID, and changing uniqueId

        regionBootstrap = new RegionBootstrap(this, region);
    }

    @Override
    public void didDetermineStateForRegion(int arg0, Region arg1) {
        Boolean isInRegion = arg0 == 1;
        Log.d(TAG, "Got a didDetermineStateForRegion call, isInRegion: " + isInRegion.toString());
    }

    @Override
    public void didEnterRegion(Region arg0) {
        Log.d(TAG, "Got a didEnterRegion call");
    }

    @Override
    public void didExitRegion(Region arg0) {
        Log.d(TAG, "Got a didExitRegion call");
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.regionmonitor"
    >

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <application
        android:name="com.example.regionmonitor.App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        >

        <!-- Note:  the singleInstance below is important to keep two copies of your activity from getting launched on automatic startup -->
        <activity
            android:launchMode="singleInstance"
            android:name="com.example.regionmonitor.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

</manifest>

MainActivity.java Should be irrelevant but for the sake of sharing all code: MainActivity.java应该无关紧要,但是为了共享所有代码:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

On Android 6+, it is no longer sufficient to put location permission in the manifest. 在Android 6+上,将位置权限放入清单中已不再足够。 You also have to request permission from the user dynamically. 您还必须动态地向用户请求权限。 Until the user grants permission, beacon detections (and all bluetooth LE scanning) is blocked. 在用户授予许可之前,信标检测(以及所有蓝牙LE扫描)将被阻止。

See here for instructions: https://altbeacon.github.io/android-beacon-library/requesting_permission.html 有关说明,请参见此处: https : //altbeacon.github.io/android-beacon-library/requesting_permission.html

The posted code works for Kontakt beacons (and IBeacons), but you need to be patient. 发布的代码适用于Kontakt信标(和IBeacons),但您需要耐心等待。 If you wait long enough the callbacks are called as expected, but it might take a while . 如果等待时间足够长,则将按预期方式调用回调, 但是可能需要一段时间

If you are testing on Nokia (like me) you might want to read this . 如果您正在像我一样在诺基亚上进行测试,则可能需要阅读本内容

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

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