@ RequiresPermission ( ACCESS_WIFI_STATE ) public static Observable < Integer > observeWifiSignalLevel ( final Context context , final int numLevels ) { final WifiManager wifiManager = ( WifiManager ) context . getSystemService ( Context . WIFI_SERVICE ) ; final IntentFilter filter = new IntentFilter ( ) ; filter . addAction ( WifiManager . RSSI_CHANGED_ACTION ) ; return Observable . create ( new ObservableOnSubscribe < Integer > ( ) { @ Override public void subscribe ( final ObservableEmitter < Integer > emitter ) throws Exception { final BroadcastReceiver receiver = createSignalLevelReceiver ( emitter , wifiManager , numLevels ) ; if ( wifiManager != null ) { context . registerReceiver ( receiver , filter ) ; } else { emitter . onError ( new RuntimeException ( "WifiManager is null, so BroadcastReceiver for Wifi signal level " + "cannot be registered" ) ) ; } Disposable disposable = disposeInUiThread ( new Action ( ) { @ Override public void run ( ) { tryToUnregisterReceiver ( context , receiver ) ; } } ) ; emitter . setDisposable ( disposable ) ; } } ) . defaultIfEmpty ( 0 ) ; }
Observes WiFi signal level . Returns WiFi signal level as an integer