2. Acquire a PARTIAL_WAKE_LOCK, and trap when the screen goes off.
Then disable and reenable the wifi. This works because the filter
only turns on when the screen goes off, so starting wifi with the
screen off will keep it working until the screen goes off again. This
is what we did before we figured out solution (1).
--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
Do you know if the same is true of (link-local) multicast?
-- Juliusz
public class ScreenStateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.i("Check", "Screen went OFF");
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"MyWakelockTag");
wakeLock.acquire();
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
new Thread(
new Runnable() {
public void run() {
try {
if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
Log.i("Check Wifi: ", "Disabled");
}
Thread.sleep(1000);
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
WifiManager.MulticastLock multicastLock = wifiManager.createMulticastLock("lockWifiMulticast");
multicastLock.acquire();
WifiManager.WifiLock wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF,"MyWifiLock");
wifiLock.acquire();
Log.i("Check Wifi: ", "Enabled");
}
}
catch(InterruptedException e) {
}
}
}).start();
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
Log.i("Check","Screen went ON");
}
}
}
Hi Hackborn,