Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
即使应用程序位于后台,android也会更新位置_Android_Location_Background Process_Android Geofence - Fatal编程技术网

即使应用程序位于后台,android也会更新位置

即使应用程序位于后台,android也会更新位置,android,location,background-process,android-geofence,Android,Location,Background Process,Android Geofence,我有一个应用程序,使用谷歌地图地理围栏。(每当用户进入围栏时,它会触发一个处理事件的pendingent) 问题是,我似乎无法让我的应用程序在后台更新位置 我当前的代码如下所示 protected void createLocationRequest() { LocationRequest mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(INTERVAL_IN_MILLI

我有一个应用程序,使用谷歌地图地理围栏。(每当用户进入围栏时,它会触发一个处理事件的
pendingent

问题是,我似乎无法让我的应用程序在后台更新位置

我当前的代码如下所示

protected void createLocationRequest() {
        LocationRequest mLocationRequest = new LocationRequest();
        mLocationRequest.setInterval(INTERVAL_IN_MILLISECONDS);
        mLocationRequest.setFastestInterval(FASTEST_INTERVAL_MILLISECONDS);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(this, "user permissions have blocked the app from getting location updates", Toast.LENGTH_SHORT).show();
            return;
        }
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    }
在我的活动中,使用更改侦听器

@Override
    public void onLocationChanged(Location location) {
        Toast.makeText(this, "testing message, at location " + location, Toast.LENGTH_SHORT).show();
    }
当应用程序在前台时,我会得到位置更新,OnLocationChanged和我的GeoFence都被正确触发,这一点很明显。但是当应用程序在后台时,我的地理围栏在我进入应用程序之前不会被触发

我甚至不需要回电话,只需要手机检查一下它的当前位置


有没有办法在后台获得位置更新

可能重复快速回答(现在办公室)1。2.我目前正在查看代码,如果我通过了,将更新此答案。1处的代码似乎一直在检查位置(即使我将间隔更改为30秒)。这将是一个巨大的电池耗电量:/可能是