0

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?

babybob
  • 444
  • 6
  • 22
  • 1
    see 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 Answers2

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
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 Intents.

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