展会信息港展会大全

Android check the net and go to the setting acvivity by intent
来源:互联网   发布日期:2016-01-14 09:28:21   浏览:931次  

导读:we used need to check the user's net is work before we need to connect the work.how can we do this? just see the code: private void checkNet(){ ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVI...

we used need to check the user's net is work before we need to connect the work.how can we do this?

just see the code:

private void checkNet(){

ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo info = cm.getActiveNetworkInfo();

if(info !=null && info.isConnected()){

Toast.makeText(this, "net is working", 0).show();

}else{

Toast.makeText(this, "net isn't work", 0).show();

// jump to the setting

Intent intent = new Intent();

intent.setClassName("com.android.setting", "com.android.settings.WirelessSettings");

startActivity(intent);

}

}

and u need to add the permission to ur AndroidManifest.xml:

android.permission.ACCESS_NETWORK_STATE

赞助本站

人工智能实验室

相关热词: android开发

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港