我的程序在启动的时候需要检测是否有网络,没有网络时打开网络设置界面,代码如下:
- Intent intentToNetwork = new Intent("/");
- ComponentName componentName = new ComponentName(
- "com.android.settings",
- "com.android.settings.WirelessSettings");
- intentToNetwork.setComponent(componentName);
- intentToNetwork.setAction("android.intent.action.VIEW");
- startActivity(intentToNetwork);
- if(android.os.Build.VERSION.SDK_INT > 10 ){
- startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
- }else {
- startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
- }
特写出来希望对出现此问题的同行有些许帮助。
原文:http://blog.youkuaiyun.com/tovey19911011/article/details/8604803