I'm creating a service called WifiMonitoring which will turn off Wifi when the connection is lost. I'm using a broadcastreceiver to receive the intent, which in-turn call the service. But now I'm stuck. Can I disable the wifi on receiving the intent in the OnReceive() method in the broadcastreceiver itself ? Is that possible to create a standalone broadcastreceive in android?
Asked
Active
Viewed 315 times
0
-
1see here, maybe it helps:http://stackoverflow.com/questions/10909683/launch-android-application-without-main-activity-and-start-service-on-launching – Opiatefuchs Nov 19 '16 at 07:20
2 Answers
3
Yes it is possible to change wifi from broad cast receiver...Give the following permissions to your App's Manifest file ACCESS_WIFI_STATE, CHANGE_WIFI_STATE And add the following code within the broadcast receiver
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);

Jayamurugan
- 542
- 2
- 10
-
Thank u for the reply pal. But my app does not have any activity. Is that possible then? If yes then how do i install it? – babybob Nov 19 '16 at 07:18
-
yes it is possible, create a separate broadcast receiver class and call it in service – Jayamurugan Nov 19 '16 at 07:23
0
Unless your app is a system app, you must have at least one Activity
and the user must explicitly start your app at least once. Otherwise your app will always be in the "stopped state" and it will never receive the broadcast Intent
s.

David Wasser
- 93,459
- 16
- 209
- 274