Android - Network State broadcast receiver does not receive intent

只愿长相守 提交于 2019-12-04 11:35:31

You can able to use this:

At first add this before @Override

private boolean isConnected = true;
private Context c;

Then use it

//check for connectivity:
ConnectivityManager connectivityManager = (ConnectivityManager) 
c.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo TestConnetion = connectivityManager.getActiveNetworkInfo();
if (TestConnetion == null){
isConnected=false;  
}

Try using this action instead:

Intent.ACTION_AIRPLANE_MODE_CHANGED

Edit

Or for all network state changes, use:

"android.intent.action.SERVICE_STATE"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!