Posts

Showing posts from November, 2013

Android: Starting Wifi scan and using ScanResult

For scanning wifi access points at interval of 30 seconds, I have the following code. However I strongly discourage frequent scanning as it will drain the battery very fast. Following code registers for a broadcast receiver and requests the Wifi scan. new Thread( ) { public void run( ) { WifiManager manager = (WifiManager) Main.getInstance( ).getContext( ) .getSystemService( Context.WIFI_SERVICE ); while ( true ) { IntentFilter i = new IntentFilter( ); i.addAction( WifiManager.SCAN_RESULTS_AVAILABLE_ACTION ); Main.getInstance( ).getContext( ).registerReceiver( new WifiScanCompleteReceiver( ), i ); boolean a = manager.startScan(); try { Thread.sleep( 30000 ); } catch ( InterruptedException e ) { } Log.d( HelperUtils.getInstance( ).getApplicationName( ), "New Wifi scan started." ); } } } .start( ); In this code Main.getInstance( ).getContext( ) returns _context = getApplicationContext( ) . Next write a broadcast receiver to liste...
A good link for Android developers. Power usage by various components in Android. https://source.android.com/devices/tech/power.html Types of coroutine scopes https://vladsonkin.com/android-coroutine-scopes-how-to-handle-a-coroutine/