同时获得网络信息ConnectivityManager崩溃 [英] ConnectivityManager is crashing while getting network info
本文介绍了同时获得网络信息ConnectivityManager崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来的Android和当我给下面的代码片段,我的Android应用程序崩溃。
I am new to android and when i give the following snippet, my android application is crashing.
ConnectivityManager manager= (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); // Application is crashing in this line.
我还检查了那里我给了互联网允许应用程序的AndroidManifest.xml中。任何帮助将是我今后的工作真的很有用。
I also checked the androidmanifest.xml where i gave the internet permission to the application. Any help would be really useful for my further work.
-Thanks,
罗恩..
-Thanks, Ron..
推荐答案
我不知道你想要说什么,但如果你想检查互联网连接,那么你可以使用这个code
I am not sure what you want to say but if you want to check internet connection then you can use this code
/**
* THIS IS FUNCTION FOR CHECKING INTERNET CONNECTION
* @return TRUE IF INTERNET IS PRESENT ELSE RETURN FALSE
*/
public boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
return (activeNetworkInfo != null && activeNetworkInfo.isAvailable() && activeNetworkInfo.isConnected());
}
和不要忘记
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
这篇关于同时获得网络信息ConnectivityManager崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文