0

我用三部手机测试了这段代码。它适用于其中两个,但不适用于第三个Huawei y9 2019。有什么问题?, 为什么会显示 (?) 和 (*) 符号?

我的代码是:

mFusedLocationProviderClient = new FusedLocationProviderClient(this);
    mLocationRequest = LocationRequest.create();
    mLocationRequest.setInterval(1000);
    mLocationRequest.setFastestInterval(500);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);


    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

        return;
    }

    mFusedLocationProviderClient.requestLocationUpdates(
            mLocationRequest,
            new LocationCallback() {
                @Override
                public void onLocationResult(LocationResult locationResult) {


                    if(locationResult != null){
                        Log.i("Your_Location",locationResult.getLastLocation().toString()+"\n\nrequestLocationUpdates() isCall");
                        textView.setText(locationResult.getLastLocation().toString());
                    }
                    else{
                        Log.i("Your_Location"," requestLocationUpdates() isCall Please Give Permission and On Location");
                        textView.setText("Please Give Permission and On Location");
                    }
                    super.onLocationResult(locationResult);


                }
            },
            getMainLooper()


    );

在此处输入图像描述

4

1 回答 1

0

我已经检查过华为以前的版本和其他手机,它对我来说工作正常。但我没有华为 y9 2019。所以你可以检查一下这个代码。

//通过FusedLocationApi请求位置

public void registerRequestUpdate(final LocationListener listener) {
        mLocationRequest = LocationRequest.create();
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        localStorageInterval=sm.getLocalStorageInterval().get("localStorageInterval")*1000;
        mLocationRequest.setInterval(NOTIFY_INTERVAL/2); // every second


        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                try {
                    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, listener);
                } catch (SecurityException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                    if (!isGoogleApiClientConnected()) {
                        mGoogleApiClient.connect();
                    }

                    registerRequestUpdate(listener);
                 //   saveLocationAndSync();

                }
            }
        }, NOTIFY_INTERVAL);
    }

// 从此方法获取更新的位置

 @Override
    public void onLocationChanged(Location location) {
        try {
              string lat = location.getLatitude(); 
              string long = location.getLongitude();

            }
        }catch (Exception ex){
            //exception
        }
    }
于 2018-12-26T07:06:50.220 回答