本文介绍了检查设备是否可以连接互联网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遵循了继续检查设备是否具有互联网连接使用
BroadcastReceiver,问题是该怎么称呼
BroadcastReceiver, the problem is how to call this
registerReceiver(mConnReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
来自主要活动
推荐答案
您有两个选择
1.在您的MainActivity.java
1. in your MainActivity.java
// create object of receiver class
NetworkChangeReceiver mConnReceiver = new NetworkChangeReceiver();
//register the receiver
registerReceiver(mConnReceiver,new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
2.在manifest
文件
2. In manifest
file
<receiver android:name=".NetworkChangeReceiver" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
这篇关于检查设备是否可以连接互联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!