如何查找网络能够在Android状态? [英] How to find Network enable status in android?
本文介绍了如何查找网络能够在Android状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能找到能上网使用意图在广播接收器在Android中请帮助我吗?正是我想要的后台进程,当应用程序不公开,我想检测网络状态
Is there possible to find internet enable using intent in broadcast receiver in android pls help me? I want exactly background process when app is not open i want to detect network status
推荐答案
试试这个低于code,
try this below code,
public class ConnectionAvailable extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(context.CONNECTIVITY_SERVICE);
boolean is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.isConnectedOrConnecting();
boolean isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.isConnectedOrConnecting();
if (!is3g && !isWifi) {
Toast.makeText(context, "Internet Connection Lost",
Toast.LENGTH_LONG).show();
} else {
if ((intent.getAction() != null)
&& (intent.getAction()
.equals("android.intent.action.AIRPLANE_MODE"))) {
Toast.makeText(context, "Internet Connection Lost",
Toast.LENGTH_LONG).show();
}
}
}
}
这可能会帮助你。
这篇关于如何查找网络能够在Android状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文