GnssStatus.Callback 在 android 8 中不起作用

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

我用过

public class MyGPSStatusV24 extends GnssStatus.Callback {

        @Override
        public void onStarted() {
            super.onStarted();
            myLogApp.log("[onGpsStatusChanged] GPS_EVENT_STARTED...");

        }

        @Override
        public void onStopped() {
            super.onStopped();
            myLogApp.log("[onGpsStatusChanged] GPS_EVENT_STOPPED...");

        }

        @Override
        public void onSatelliteStatusChanged(GnssStatus status) {
            super.onSatelliteStatusChanged(status);
            myLogApp.log("[onGpsStatusChanged] onSatelliteStatusChanged...");
        }

        @Override
        public void onFirstFix(int ttffMillis) {
            super.onFirstFix(ttffMillis);
            myLogApp.log("[onGpsStatusChanged] GPS_EVENT_FIRST_FIX...");

        }
    }

用于检查 Android 8 中的 GPS 状态。

主要有:

mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            mlocListener = new MyLocationListener();

            if(Build.VERSION.SDK_INT < Build.VERSION_CODES.N ){
                ...
            }else{
                mlocManager.registerGnssStatusCallback(new MyGPSStatusV24());
            }
            mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

但是MyGPSStatusV24中的方法从未被触发。

即使我禁用 GPS,onStopped 也不会被触发。

我已经在 Android 7 设备中尝试过这段代码并且可以工作,但是当我使用 google Pixel 时却无法工作。我不知道这是否是 Android 8 中 google Pixel o 的错误。

android gps android-8.0-oreo google-pixel
2个回答
0
投票

是的,当我将目标更新到 API 33 时,它失败并表示已弃用。但这将一直有效到 API 31 请参阅此链接

我们需要使用代码示例中给出的GnssStatus


-2
投票

好的,我已经测试过了,Bug 是来自设备,而不是编解码器错误。

© www.soinside.com 2019 - 2024. All rights reserved.