开关Android的APN网络的实现
2010-08-21 06:20:00 来源:WEB开发网/**
* 中国移动cmnet
*/
public static String CMNET = "cmnet";
//中国联通3GWAP设置 中国联通3G因特网设置 中国联通WAP设置 中国联通因特网设置
//3gwap 3gnet uniwap uninet
/**
* 3G wap 中国联通3gwap APN
*/
public static String GWAP_3 = "3gwap";
/**
* 3G net 中国联通3gnet APN
*/
public static String GNET_3="3gnet";
/**
* uni wap 中国联通uni wap APN
*/
public static String UNIWAP="uniwap";
/**
* uni net 中国联通uni net APN
*/
public static String UNINET="uninet";
}
public static String matchAPN(String currentName) {
if("".equals(currentName) || null==currentName){
return "";
}
currentName = currentName.toLowerCase();
if(currentName.startsWith(APNNet.CMNET))
return APNNet.CMNET;
else if(currentName.startsWith(APNNet.CMWAP))
return APNNet.CMWAP;
else if(currentName.startsWith(APNNet.GNET_3))
return APNNet.GNET_3;
else if(currentName.startsWith(APNNet.GWAP_3))
return APNNet.GWAP_3;
else if(currentName.startsWith(APNNet.UNINET))
return APNNet.UNINET;
else if(currentName.startsWith(APNNet.UNIWAP))
return APNNet.UNIWAP;
else if(currentName.startsWith("default"))
return "default";
else return "";
// return currentName.substring(0, currentName.length() - SUFFIX.length());
}
}
最后不要忘记加上修改APN的权限:
Xml代码
< uses-permission android:name="android.permission.WRITE_APN_SETTINGS">
< uses-permission android:name="android.permission.WRITE_APN_SETTINGS">
经过测试在G1 上联通和移动卡均是成功的。
更多精彩
赞助商链接