安卓下测试网络连接是否可用的问题

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 checkNetworkInfo.isConnected() before initiating network traffic. This may returnnull when there is no default network.

Returns:
a NetworkInfo object for the current default network or null if 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之后还是一样的错误。后来在图形界面添加之后正常


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值