android 2.2和2.3apn拨号问题,难搞
现在开发的系统是和电信合作的,使用电信手机,走的不是普通的互联网,而是电信开辟的专网,其实也就是在联网的时候换个电信的特殊账号而已。大家知道,电信手机默认的net接入点“中国电信互联网设置CTNET”的用户是ctnet@mycdma.cn密码是ctnet,也可以使用card/card这个账号。使用这个连接后可以访问互联网。
现在我们的项目,电信给我们开辟新的账号:ydjw@ahga.vpdn.ah。
我的做法是 在程序启动时,通过代码新建apn,然后设置首选项为当前建立的。这样一旦成功,就可以直接通过socket连接专网了。
关于建立apn的代码,都和网上介绍的差不多,先插入“content://telephnoy/carriers”指向的数据库,然后设置"content://telephony/carriers/preferapn"指向的首选项,最后使用开源代码类NetworkConnectivityListener类监听拨号是否成功。
现在问题是,同样的代码在android2.1系统手机上是可以连接网络的,在android2.2及2.3无论如何都连接不上,看了android2.2和2.3的源码,主要看了ConnectivityService.java类,也是一头雾水啊,从日志中观察,结果如下:
从日志里可以看到标签为“ConnectivityService”和“MobileDataStateTracker”的项。
当在apn接入点里选择系统自带的接入点入“中国电信互联网设置CTNET”的时候,马上能够连接互联网,log会打印如下相关信息:
D/ConnectivityService( 110): ConnectivityChange for mobile: CONNECTED/CONNECTED
D/ConnectivityService( 110): adding dns 61.132.163.68 for mobile
D/ConnectivityService( 110): adding dns 202.102.213.68 for mobile
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
。。。。
系统监听成功,还设置dns。对比2.1系统,似乎没有设置dns的过程,2.1系统在这2个类里源码就有区别的。
但是选择自己建立的接入点时会一直打印:
D/ConnectivityService( 110): Doing network teardown
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
D/ConnectivityService( 110): getMobileDataEnabled returning true
D/ConnectivityService( 110): ConnectivityChange for mobile: CONNECTING/CONNECTING
W/InputManagerService( 110): Got RemoteException sending setActive(false) notification to pid 199 uid 10000
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
D/ConnectivityService( 110): getMobileDataEnabled returning true
D/ConnectivityService( 110): ConnectivityChange for mobile: CONNECTING/CONNECTING
D/ConnectivityService( 110): ignoring stopUsingNetworkFeature - not a live request
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
D/ConnectivityService( 110): getMobileDataEnabled returning true
。。。。。
似乎必须使用电信自带的用户名和密码才能连接网络,其他账号就是连接不上。
求各位大牛,看下有没有做过在android2.2或2.3系统,自己建立apn连接网络的项目,给指点下,万分感激!
现在我们的项目,电信给我们开辟新的账号:ydjw@ahga.vpdn.ah。
我的做法是 在程序启动时,通过代码新建apn,然后设置首选项为当前建立的。这样一旦成功,就可以直接通过socket连接专网了。
关于建立apn的代码,都和网上介绍的差不多,先插入“content://telephnoy/carriers”指向的数据库,然后设置"content://telephony/carriers/preferapn"指向的首选项,最后使用开源代码类NetworkConnectivityListener类监听拨号是否成功。
现在问题是,同样的代码在android2.1系统手机上是可以连接网络的,在android2.2及2.3无论如何都连接不上,看了android2.2和2.3的源码,主要看了ConnectivityService.java类,也是一头雾水啊,从日志中观察,结果如下:
从日志里可以看到标签为“ConnectivityService”和“MobileDataStateTracker”的项。
当在apn接入点里选择系统自带的接入点入“中国电信互联网设置CTNET”的时候,马上能够连接互联网,log会打印如下相关信息:
D/ConnectivityService( 110): ConnectivityChange for mobile: CONNECTED/CONNECTED
D/ConnectivityService( 110): adding dns 61.132.163.68 for mobile
D/ConnectivityService( 110): adding dns 202.102.213.68 for mobile
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
。。。。
系统监听成功,还设置dns。对比2.1系统,似乎没有设置dns的过程,2.1系统在这2个类里源码就有区别的。
但是选择自己建立的接入点时会一直打印:
D/ConnectivityService( 110): Doing network teardown
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
D/ConnectivityService( 110): getMobileDataEnabled returning true
D/ConnectivityService( 110): ConnectivityChange for mobile: CONNECTING/CONNECTING
W/InputManagerService( 110): Got RemoteException sending setActive(false) notification to pid 199 uid 10000
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
D/ConnectivityService( 110): getMobileDataEnabled returning true
D/ConnectivityService( 110): ConnectivityChange for mobile: CONNECTING/CONNECTING
D/ConnectivityService( 110): ignoring stopUsingNetworkFeature - not a live request
D/ConnectivityService( 110): ConnectivityChange for mobile: DISCONNECTED/DISCONNECTED
D/ConnectivityService( 110): getMobileDataEnabled returning true
。。。。。
似乎必须使用电信自带的用户名和密码才能连接网络,其他账号就是连接不上。
求各位大牛,看下有没有做过在android2.2或2.3系统,自己建立apn连接网络的项目,给指点下,万分感激!
...全文
相关推荐
android 设置apn
android 设置apn,包括自动和手动,成熟代码
android2.3.5 CDMA/EVDO拨号APN解决方案
google提供的android2.3里面,只能在GSM/WCDMA情况下才能从“设置”->“无线和网络”->“移动网络”->“接入点名称”中选择不同的apn帐号进行拨号连接,而CDMA/EVDO则没有这个功能,接下来本文介绍一些方法实现这个功能,感兴趣的朋友可以了解下
android APN开发流程
android APN开发流程
android当前apn的状态以及获取方法
在绝大多数android机器etc路径下存放一个的apns-conf.xml文件,表示当前机器使用的apn信息通过root机器可以push出来看看,具体路径可以上网搜下,接下来介绍获取apn的状态的方法
获取和修改手机当前APN
通过修改androidprovider。java源码,实现修改和获取APN的接口


