使用PRIORITY_HIGH_ACCURACY的位置问题,settings.api的对话框不启用gps

时间:2015-12-27 08:46:32

标签: android gps location google-play-services

我正在使用播放服务中的位置设置,并且在棒棒糖前工作正常,但在棉花糖中,gps未启用,既没有显示也没有显示在对话框中,即将使用gps仅使用wifi和蜂窝网络,以及位置模式更改仅节省电池。

对不起我的英语我来自墨西哥。 这是我的代码:

public void ActivarWifiGps(boolean gpsrequerido){
        //Toast.makeText(getApplicationContext(), "se llamo al popup", Toast.LENGTH_SHORT).show();
        Log.i("sms", "se llamo al popup");
        mGoogleApiClient = new GoogleApiClient
                .Builder(this).
                addApi(LocationServices.API)
                .build();

     mGoogleApiClient.connect();

       mLocationRequest.setInterval(1000);
      mLocationRequest.setFastestInterval(FATEST_INTERVAL);
        if(gpsrequerido) {
            //EVEN ENTER HERE...
            Log.i("sms", "se usara gps");
            mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        }else{
            Log.i("sms", "se usara wifi");
            mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
        }
        mLocationRequest.setSmallestDisplacement(10);

        builder = new LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest);
        builder.setAlwaysShow(true);


       // builder.setNeedBle(true);
        PendingResult<LocationSettingsResult> result =
                LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());

        result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
            @Override
            public void onResult(LocationSettingsResult result) {


                final Status status = result.getStatus();
                final LocationSettingsStates state = result.getLocationSettingsStates();
                switch (status.getStatusCode()) {
                    case LocationSettingsStatusCodes.SUCCESS:
                        // All location settings are satisfied. The client can initialize location
                        // requests here.
                        //...}





                            Log.i("sms", "todo bien");
                            obj.comenzar();



                        Log.i("sms", "estan disponibles");
                       // Toast.makeText(MainActivity.this, "HOLA 1", Toast.LENGTH_SHORT).show();
                        break;
                    case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                        // Location settings are not satisfied. But could be fixed by showing the user
                        // a dialog.

                        Log.i("sms", "Motrando popup");
                        //  if( !state.isNetworkLocationPresent()|| !state.isLocationUsable()){

                        //Toast.makeText(MainActivity.this, "HOLA 2", Toast.LENGTH_SHORT).show();
                        try {
                            // Show the dialog by calling startResolutionForResult(),
                            // and check the result in onActivityResult().
                            status.startResolutionForResult(
                                    MainActivity.this,
                                    REQUEST_CHECK_SETTINGS);
                        } catch (IntentSender.SendIntentException e) {
                            // Ignore the error.
                        }
                        // }
                        break;
                    case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                        //Toast.makeText(MainActivity.this, "HOLA 3", Toast.LENGTH_SHORT).show();
                        // Location settings are not satisfied. However, we have no way to fix the
                        // settings so we won't show the dialog.
                        //...
                        break;
                }
            }
        });
    }

这是对话框: enter image description here

0 个答案:

没有答案