Actually In my app I have to show the toggle button on/off if mobile data packect on/off.
But there is a problem my local boradcast can't listen mobile data packet on/off event if my WiFi is already on. Actually as I understand If my WiFi on then mobile data packet enable and disable event never affect connectivity status. Thats why my some intent filter never works.
android.net.conn.CONNECTIVITY_CHANGE
I need a intent filter which is similer to android.net.wifi.WIFI_STATE_CHANGED so that whenever mobile data packet on or off event fire my broadcast can listen it easily. And I can change my widget.
I dont know of any intent-filter
that we could receive when the mobile data is turned on or off but the following code is to determine whether mobile data is turn on or off.
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if(connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected())
//mobile data is on
else
//mobile data is off
What you can do is write a service of your own that will constantly run the above code. When the mobile data is on, you can send a broadcast to your activity telling the same. Same goes when the mobile data is off.
Edit1:- This works even if wi-fi is connected.
Edit2:- Don't forget to add ACCESS_NETWORK_STATE
permission while using this