如何在不进行位置重新设置的情况下调用“ startResolutionForResult()”?

时间:2019-06-30 09:42:26

标签: android kotlin google-maps-android-api-2 fusedlocationproviderapi

如果不发出位置请求,我将无法致电startResolutionForResult()。我正在使用FusedLocationProvider API来获取Google Maps V2中的用户位置更新:

    val builder = LocationSettingsRequest.Builder().addLocationRequest(mLocationRequest)
    val client = LocationServices.getSettingsClient(this)
    val task = client!!.checkLocationSettings(builder!!.build())

    task!!.addOnSuccessListener {
        mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper())
        val serviceIntent = Intent(this@MainActivity, LocationService::class.java)
        startService(serviceIntent)
    }.addOnFailureListener { exception ->
        if (exception is ResolvableApiException) {
            try {
                exception.startResolutionForResult(this@MainActivity, 11351)
            } catch (throwable: Throwable) {
                // Ignore the error.
            }
        }
    }

我想做的是在不发出位置请求的情况下呼叫startResolutionForResult()

0 个答案:

没有答案