小编asi*_*ura的帖子

适用于Android的Google Play服务.如果禁用wifi,位置客户端不会更新位置

我们的应用程序请求使用LocationClient和IntentService更新位置.如果用户在手机设置中禁用wifi,则位置根本不会更新.

我们尝试使用PRIORITY_HIGH_ACCURACY测试应用,并在禁用wifi时更新位置信息.

如果用户在没有wifi网络可用的地方移动,则会出现同样的问题.

如果手机无法通过wifi更新位置,我认为正确的行为是使用其他手机传感器(如GPS)进行更新.

重现步骤:

  1. 使用待定意图启动更新位置.带参数

    LocationRequest request = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
            .setInterval(5 * 60 * 1000)
            .setFastestInterval(60*1000)
            .setSmallestDisplacement(70);
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在手机设置中禁用wifi或在没有无线网络的国家/地区使用手机.

在Android 4.4,4.3,4.1,4.0,2.3.3上测试过.(Nexus7,Nexus4,三星GS2,HTC Wildfire等)

public class TrackerService extends IntentService {
    private void startUpdateLocation() {
        PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(),
            0, new Intent(ACTION_LOCATION_UPDATED), 0);
        LocationRequest request = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY)
            .setInterval(5 * 60 * 1000)
            .setFastestInterval(60*1000)
            .setSmallestDisplacement(70);

        getLocationClient().requestLocationUpdates(request, pendingIntent);
        Log.d(Utils.getMethodName(), "Location update started");
    }

    private LocationClient getLocationClient() {
        if (mLocationClient != null && mLocationClient.isConnected()) return mLocationClient;
        mLocationClient = new LocationClient(this,
            new GooglePlayServicesClient.ConnectionCallbacks() {
                @Override
                public …
Run Code Online (Sandbox Code Playgroud)

android location google-play-services

19
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

google-play-services ×1

location ×1