安卓下测试网络连接是否可用的问题
2014-08-26 09:54
399 查看
API文档内容:
NetworkInfo android.net.ConnectivityManager.getActiveNetworkInfo()
Returns details about the currently active default data network. When connected, this network is the default route for outgoing connections. You should always check
NetworkInfo.isConnected()before
initiating network traffic. This may return
nullwhen there is no default network.
Returns:a
NetworkInfoobject for the current default network or
nullif no network default network is currently active
This method requires the call to hold the permission
android.Manifest.permission.ACCESS_NETWORK_STATE.
API里提到的权限是
android.Manifest.permission.ACCESS_NETWORK_STATE.
实际执行的时候却报错
08-26 09:14:44.896: E/AndroidRuntime(12009): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testnetwork/com.example.testnetwork.MainActivity}: java.lang.SecurityException: ConnectivityService: Neither user 10102 nor current process has android.permission.ACCESS_NETWORK_STATE. 08-26 09:16:47.651: E/AndroidRuntime(12276): Caused by: java.lang.SecurityException: ConnectivityService: Neither user 10102 nor current process has android.permission.ACCESS_NETWORK_STATE.
报错提示缺少权限android.permission.ACCESS_NETWORK_STATE.
添加之后正常,但是有个小细节,添加权限的时候不能在代码里面添加,应该是个bug,我在代码里面添加之后任然报这个错,即使clean了工程重启eclipse之后还是一样的错误。后来在图形界面添加之后正常
相关文章推荐
- 关于“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决
- android中判断网络连接是否可用
- [Android开发常见问题-6] 如何检测手机当前网络是否可用?
- android 判断网络连接是否可用
- Android中判断网络连接是否可用及监控网络状态
- 在PB程序中如何测试网络连接是否中断
- Android中判断网络连接是否可用
- android中判断网络连接是否可用
- Android判断网络连接是否可用(代码)
- PB程序中如何测试网络连接是否中断?(实现Ping命令)
- PB程序中如何测试网络连接是否中断?
- 用API测试是否连接网络!
- Android中判断网络连接是否可用
- 检查Android网络连接是否可用
- Android 判断当前网络连接是否可用、打开设置网络界面
- android 程序中判断当前是否连接网络,网络是否可用
- C#快速检测是否有可用的网络连接存在
- Android中判断网络连接是否可用及监控网络状态
- Android开发_判断网络连接是否可用
- Android中判断网络连接是否可用