0

在 Oreo 8.0 和 8.1 发布后,我将我的 targetSdkVersion 更新为 27,因为通知通道是前台服务所必需的,但不幸的是,如果设备未连接到 Internet,FusedLocationProviderClient 将停止工作,但只有在再次连接到 Internet 时才会恢复。该服务仍在运行,因此通知仍然存在。我试过寻找答案,但我没有看到任何与我的问题相关的问题,如果我没记错的话,也许是因为 SDKversion 27 是最新的。下面是我做 FusedLocationProviderClient 的方法。先感谢您

 long interval=locationInterval*1000L;

        final LocationRequest locationRequest=
                LocationRequest.create()
                        .setInterval(interval)
                        .setFastestInterval(interval)
                        .setSmallestDisplacement(0)
                        .setPriority(getLocationRequestPriority);

        // Create LocationSettingsRequest object using location request
        LocationSettingsRequest.Builder builder = new 
        LocationSettingsRequest.Builder();
        builder.addLocationRequest(locationRequest);
        LocationSettingsRequest locationSettingsRequest = builder.build();
        final SettingsClient settingsClient = 
        LocationServices.getSettingsClient(context);
        settingsClient.checkLocationSettings(locationSettingsRequest);

        mLocationCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {
                super.onLocationResult(locationResult);

                startTrackingUserActivity();
                evaluateLoopEvent(locationResult.getLastLocation(),context);

            }
        };

        fusedLocationProviderClient.requestLocationUpdates(locationRequest,
                mLocationCallback,
                null /* Looper */);

注意:在 6.0 及更高版本中一切正常,仅在 5.0 中无法正常工作。以下是我关闭wifi后的日志,但似乎这些与我猜的问题不太相关,但只是为了确保:

  10-11 17:29:37.556 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 requestNextVsync
10-11 17:29:37.564 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 44149(2MB) AllocSpace objects, 0(0B) LOS objects, 14% free, 23MB/27MB, paused 1.398ms total 122.731ms
10-11 17:29:37.572 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 latestVsyncEvent 7443515544577
10-11 17:29:58.061 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 requestNextVsync
10-11 17:29:58.062 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 latestVsyncEvent 7464005223098
10-11 17:30:20.936 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 57947(3MB) AllocSpace objects, 0(0B) LOS objects, 15% free, 22MB/26MB, paused 1.815ms total 130.586ms
10-11 17:30:55.554 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 requestNextVsync
10-11 17:30:55.569 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 latestVsyncEvent 7521510589393
10-11 17:31:05.212 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 37227(2MB) AllocSpace objects, 0(0B) LOS objects, 15% free, 22MB/26MB, paused 1.884ms total 102.828ms
10-11 17:31:47.335 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 36922(2MB) AllocSpace objects, 0(0B) LOS objects, 15% free, 22MB/26MB, paused 1.494ms total 103.556ms
10-11 17:32:01.099 3553-3572/com.mypackage I/art: Background sticky concurrent mark sweep GC freed 37651(3MB) AllocSpace objects, 0(0B) LOS objects, 7% free, 23MB/25MB, paused 6.855ms total 39.761ms
10-11 17:32:50.283 3553-3553/com.mypackage V/InputMethodManager: onWindowFocus: android.support.v7.widget.RecyclerView{119be94e VFED.... .F...... 0,0-600,854 #7f090150 app:id/recycler_view} softInputMode=16 first=false flags=#81810100
10-11 17:33:15.775 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 37311(2MB) AllocSpace objects, 0(0B) LOS objects, 15% free, 22MB/26MB, paused 1.446ms total 101.032ms
10-11 17:33:22.139 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 requestNextVsync
10-11 17:33:22.153 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 latestVsyncEvent 7668096397615
10-11 17:33:40.051 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 requestNextVsync
10-11 17:33:40.056 3553-9897/com.mypackage D/OpenGLRenderer: DisplayEventReceiver 0xb0615050 latestVsyncEvent 7685998917119
10-11 17:33:57.871 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 36892(2MB) AllocSpace objects, 0(0B) LOS objects, 15% free, 22MB/26MB, paused 1.661ms total 109.571ms
10-11 17:34:11.621 3553-3572/com.mypackage I/art: Background sticky concurrent mark sweep GC freed 37628(3MB) AllocSpace objects, 0(0B) LOS objects, 7% free, 23MB/25MB, paused 6.664ms total 38.293ms
10-11 17:34:43.011 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 37327(2MB) AllocSpace objects, 0(0B) LOS objects, 15% free, 22MB/26MB, paused 1.452ms total 106.040ms
10-11 17:35:27.299 3553-3572/com.mypackage I/art: Background partial concurrent mark sweep GC freed 37212(2MB) AllocSpace objects, 0(0B) LOS objects, 15% free, 22MB/26MB, paused 1.420ms total 108.233ms
4

0 回答 0