Tener un indicador de modo sin connection en Mapbox

No soy muy bueno en la encoding y actualmente uso la API de Mapbox para crear un map con puntos. Pero no puede encontrar nada al mostrar un indicador cuando el dispositivo no tiene internet. En una palabra, mostrar el estado de Internet en mapbox es mi objective. He intentado con la encoding de BroadcastReceiver, aquí está mi código

Mi NetworkStateChangeReceiver.java:

public class NetworkStateChangeReceiver extends BroadcastReceiver { public static final String NETWORK_AVAILABLE_ACTION = "com.viseo.poc.jooboot.NetworkAvailable"; public static final String IS_NETWORK_AVAILABLE = "isNetworkAvailable"; @Override public void onReceive(Context context, Intent intent) { Intent networkStateIntent = new Intent(NETWORK_AVAILABLE_ACTION); networkStateIntent.putExtra(IS_NETWORK_AVAILABLE, isConnectedToInternet(context)); LocalBroadcastManager.getInstance(context).sendBroadcast(networkStateIntent); } private boolean isConnectedToInternet(Context context) { try { if (context != null) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); return networkInfo != null && networkInfo.isConnectedOrConnecting(); } return false; } catch (Exception e) { Log.e(NetworkStateChangeReceiver.class.getName(), e.getMessage()); return false; } } } 

Mi MapActivity.kt

 class MapActivity : BasePermissionActivity() { private var map: MapboxMap? = null private var locationServices: LocationServices? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) //MapBox SDK MapboxAccountManager.start(this, getString(R.string.access_token)) setContentView(R.layout.activity_map_layout) locationServices = LocationServices.getLocationServices(this@MapActivity) // Create a mapView mapview.onCreate(savedInstanceState) // register connection status listener val intentFilter = IntentFilter(NetworkStateChangeReceiver.NETWORK_AVAILABLE_ACTION) LocalBroadcastManager.getInstance(this@MapActivity).registerReceiver(object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val isNetworkAvailable = intent.getBooleanExtra(IS_NETWORK_AVAILABLE, false) val networkStatus = if (isNetworkAvailable) "connected" else "disconnected" ToastUtil.showLong(this@MapActivity,networkStatus) } },intentFilter) mapview.getMapAsync { mapboxMap -> // Customize map with markers, polylines, etc. map = mapboxMap // Enable user tracking to show the padding affect. } } private fun showSnack() { val snackbar = Snackbar.make(findViewById(R.id.rv_container_map), "Vous êtes dans Offline Mode", Snackbar.LENGTH_INDEFINITE) val sbView = snackbar.view val textView = sbView.findViewById(android.support.design.R.id.snackbar_text) as TextView textView.setTextColor(R.color.white) snackbar.show() } override fun onResume() { super.onResume() mapview.onResume() } override fun onPause() { super.onPause() mapview.onPause() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) mapview.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() mapview.onLowMemory() } } 

AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.test"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:name=".Application" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".ui.activity.MapActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="io.fabric.ApiKey" android:value="48f1a2e2089964c945e6fbdc09272782e1f04c47" /> <receiver android:name=".utils.network.NetworkStateChangeReceiver" android:exported="false"> <intent-filter > <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> <service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService" /> </application> </manifest>