Feroz Siddiqui Feroz Siddiqui - 2 months ago 32
Android Question

how to make sure HTML Websocket seesion keep alive in Android webview

how to make sure HTML Websocket seesion keep alive in Android webview when andriod device goes in sleep mode.My enitre application is running in web view. I have used the below code:

PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Httpd");
wakeLock.acquire();

// Keep the wifi awake.
WifiManager wm = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
WifiManager.WifiLock wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Httpd");
wifiLock.acquire();


getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


and below permission

<uses-permission android:name="android.permission.WAKE_LOCK" />


Its disable the screen lock but still webssocket session is getting timeout some how

Answer

use wake lock permission,

   <uses-permission android:name="android.permission.WAKE_LOCK" />