简体   繁体   English

Altbeacon 停止在 Android10 上工作,并且根本没有调用 didEnterRegion

[英]Altbeacon stopped working on Android10 and didEnterRegion does not get called at all

altbeacon on Android 10 has simply stopped working. Android 10 上的 altbeacon 已停止工作。 Are there any changes required especially to go to Android 10?是否需要对 go 到 Android 10 进行任何更改?

I have added the following permissions to my AndroidManifest.xml我已将以下权限添加到我的AndroidManifest.xml

<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>
<uses-permission android:name=\"android.permission.BLUETOOTH\"/>
<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>
<uses-permission android:name=\"android.permission.ACCESS_BACKGROUND_LOCATION\"/>
<uses-permission android:name=\"android.permission.RECEIVE_BOOT_COMPLETED\" />
<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>

Looking at the app permissions, my app has the location and BT permissions granted while running.查看应用程序权限,我的应用程序在运行时授予了位置和 BT 权限。 I start looking for beacons on onBeaconServiceConnect as prescribed athttps://altbeacon.github.io/android-beacon-library/samples.html .我开始按照https://altbeacon.github.io/android-beacon-library/samples.ZFC35FDC70D5FC69D269883A822C onBeaconServiceConnect规定在 onBeaconServiceConnect 上寻找信标What am I missing?我错过了什么?

Android 10 adds new permissions requirements to do BLE scans and detect BLE beacons -- any app setting targetSdkVersion 29 or higher needs to obtain permissions as described below or no beacons will be detected. Android 10 增加了执行 BLE 扫描和检测 BLE 信标的新权限要求——任何设置targetSdkVersion 29或更高版本的应用程序都需要获得如下所述的权限,否则将不会检测到信标。 (If you set targetSdkVersion 28 or earlier, these new requirements do not apply when running on Android 10, as Android grants the permissions automatically. This allows old apps to continue running unaffected after upgrading to Android 10.) (如果您设置targetSdkVersion 28或更早版本,则这些新要求在 Android 10 上运行时不适用,因为 Android 会自动授予权限。这允许旧应用程序在升级到 ZE84E30B9397846DDBZDB10B939784664DZ 后继续运行不受影响)

The changes below are what you need to to if you set your project to targetSdkVersion 29 or higher:如果您将项目设置为targetSdkVersion 29或更高版本,则需要进行以下更改:

In addition to adding these permissions to the manifest:除了将这些权限添加到清单之外:

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

You must also dynamically obtain the location permissions from the user as described here:您还必须从用户那里动态获取位置权限,如下所述:

private static final int PERMISSION_REQUEST_FINE_LOCATION = 1;
    private static final int PERMISSION_REQUEST_BACKGROUND_LOCATION = 2;
...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ...


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (this.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
                    == PackageManager.PERMISSION_GRANTED) {
                if (this.checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
                        != PackageManager.PERMISSION_GRANTED) {
                    if (this.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
                        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("This app needs background location access");
                        builder.setMessage("Please grant location access so this app can detect beacons in the background.");
                        builder.setPositiveButton(android.R.string.ok, null);
                        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                            @TargetApi(23)
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                requestPermissions(new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION},
                                        PERMISSION_REQUEST_BACKGROUND_LOCATION);
                            }

                        });
                        builder.show();
                    }
                    else {
                        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Functionality limited");
                        builder.setMessage("Since background location access has not been granted, this app will not be able to discover beacons in the background.  Please go to Settings -> Applications -> Permissions and grant background location access to this app.");
                        builder.setPositiveButton(android.R.string.ok, null);
                        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface dialog) {
                            }

                        });
                        builder.show();
                    }

                }
            } else {
                if (this.shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
                    requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION,
                                    Manifest.permission.ACCESS_BACKGROUND_LOCATION},
                            PERMISSION_REQUEST_FINE_LOCATION);
                }
                else {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle("Functionality limited");
                    builder.setMessage("Since location access has not been granted, this app will not be able to discover beacons.  Please go to Settings -> Applications -> Permissions and grant location access to this app.");
                    builder.setPositiveButton(android.R.string.ok, null);
                    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                        }

                    });
                    builder.show();
                }

            }
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case PERMISSION_REQUEST_FINE_LOCATION: {
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Log.d(TAG, "fine location permission granted");
                } else {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle("Functionality limited");
                    builder.setMessage("Since location access has not been granted, this app will not be able to discover beacons.");
                    builder.setPositiveButton(android.R.string.ok, null);
                    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                        }

                    });
                    builder.show();
                }
                return;
            }
            case PERMISSION_REQUEST_BACKGROUND_LOCATION: {
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Log.d(TAG, "background location permission granted");
                } else {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle("Functionality limited");
                    builder.setMessage("Since background location access has not been granted, this app will not be able to discover beacons when in the background.");
                    builder.setPositiveButton(android.R.string.ok, null);
                    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                        }

                    });
                    builder.show();
                }
                return;
            }
        }
    }

If you do not see this working, go to Settings -> Apps -> Your App -> Permissions and verify location had been granted.如果您没有看到此操作,go 到设置 -> 应用程序 -> 您的应用程序 -> 权限并验证位置已被授予。

暂无
暂无

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

相关问题 AltBeacon库BootstrapNotifier不会调用didEnterRegion - AltBeacon library BootstrapNotifier does not call didEnterRegion 从DidEnterRegion BootstrapNotifier回调绑定BeaconConsumer时不调用AltBeacon:onBeaconServiceConnect - AltBeacon : onBeaconServiceConnect not called when BeaconConsumer Binded From DidEnterRegion BootstrapNotifier callback AltBeacon didEnterRegion()/ didExitRegion无法与PiBeacon一起正常工作。 方法被随机调用 - AltBeacon didEnterRegion()/didExitRegion not working properly with PiBeacon. Methods are randomly being called AltBeacon:didExitRegion和didEnterRegion交替 - AltBeacon: didExitRegion and didEnterRegion alternation locationmanager didenterregion未被呼叫 - locationmanager didenterregion doesn't get called Android Beacon库-对于Android 8之前的版本,应用在后台运行或停止运行时,didEnterRegion不会触发 - Android Beacon Library - didEnterRegion not firing when app in background or stopped for pre-Android 8 iBeacon:didEnterRegion永远不会被调用 - iBeacon: didEnterRegion never gets called 在目标C中未调用didEnterRegion但已调用didExitRegion - didEnterRegion is not Called but didExitRegion is Called in objective C didEnterRegion和startRangingForBeacons没有被调用 - didEnterRegion and startRangingForBeacons not being called 仅在调用requestAlwaysAuthorization时才调用DidEnterRegion。 信标 - DidEnterRegion only called if requestAlwaysAuthorization is called. Beacons
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM