मैं एक का उपयोग करके उपकरण की कनेक्टिविटी को देख रहा हूँ BroadcastReceiver। डिवाइस ऑनलाइन करने के लिए ऑफ़लाइन से अपने राज्य बदलता है, तो मैं नीचे दिए गए कोड में जैसे कुछ जियोकोडिंग प्रदर्शन करने की जरूरत है।
समस्या यह है, कि जियोकोडिंग के साथ विफल: java.io.IOException: grpc failed।
कॉल किसी भी तरह (जैसे एक ब्रेकपाइंट के कारण) में देरी हो जाती है तो जियोकोडर ठीक से काम करने लगता है।
वहाँ एक रास्ता सूचना पाने के लिए जब है android.location.Geocoderका उपयोग करने के लिए तैयार है?
// in BroadcastReceiver:
init {
context.registerReceiver(this, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
}
override fun onReceive(context: Context?, intent: Intent?) {
context?.let {
val activeNetworkInfo = (context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).activeNetworkInfo
val isConnected = activeNetworkInfo != null && activeNetworkInfo.isConnected
// if `isConnected` geocoding gets triggered
}
}
// Geocoding
var coordinate: LatLng? = null
val address = arrayOf(
location.street, location.streetNumber,
location.zipCode, location.city,
location.country
).joinToString( )
try {
val geocoder = Geocoder(context)
geocoder.getFromLocationName(address, 1).firstOrNull()?.let { result ->
coordinate = LatLng(result.latitude, result.longitude)
}
} catch (a: IOException) {
coordinate = null
}
// do something with `coordinate`













