Android通讯录开发之获取运营商号码段(移动、联通、电信)
![](https://code.csdn.net/assets/CODE_ico.png)
- <?xml version="1.0" encoding="utf-8"?>
- <config>
- <!-- 移动现有号码段 -->
- <TEL_MOBILE>
- 134,135,136,137,138,139,147,150,151,152,157,158,159,182,183,184,187,188
- </TEL_MOBILE>
- <!-- 联通现有号码段 -->
- <TEL_UNICOM>
- 130,131,132,155,156,185,186,145,176
- </TEL_UNICOM>
- <!-- 电信现有号码段 -->
- <TELECOM>
- 133,153,180,181,189,1700,177
- </TELECOM>
- </config>
![](https://code.csdn.net/assets/CODE_ico.png)
- package com.suntek.mobilemeeting.config;
- import java.io.InputStream;
- import java.util.HashMap;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import org.xml.sax.Attributes;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.DefaultHandler;
- import android.text.TextUtils;
- /**
- * 配置文件控制器 用于获取配置文件
- *
- * @author wwj
- *
- */
- public class ConfigController {
- private static ConfigController instance;
- public static ConfigController getInstance() {
- if (instance == null) {
- synchronized (ConfigController.class) {
- if (instance == null) {
- instance = new ConfigController();
- }
- }
- }
- return instance;
- }
- public ConfigController() {
- InputStream input = getClass().getResourceAsStream(
- "/res/raw/config.xml");
- try {
- config = new ConfigParser(input).getResult();
- } catch (Exception e) {
- config = new HashMap<String, String>();
- e.printStackTrace();
- }
- }
- private HashMap<String, String> config;
- public String get(String key) {
- return config.get(key);
- }
- /**
- * 获取/res/raw/config.xml中的配置
- *
- * @param key
- * 配置名
- * @param failedValue
- * 获取配置失败时的取值:没有配置,或者配置不为boolean型
- */
- public boolean get(String key, boolean failedValue) {
- String stringValue = config.get(key);
- if (TextUtils.isEmpty(stringValue)
- || !("true".equalsIgnoreCase(stringValue) || "false"
- .equalsIgnoreCase(stringValue))) {
- return failedValue;
- } else {
- return Boolean.parseBoolean(stringValue);
- }
- }
- class ConfigParser extends DefaultHandler {
- private StringBuffer accumulator;
- private HashMap<String, String> result;
- public ConfigParser(InputStream input) throws Exception {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- SAXParser parser = factory.newSAXParser();
- parser.parse(input, this);
- }
- public void characters(char buffer[], int start, int length) {
- accumulator.append(buffer, start, length);
- }
- public void endDocument() throws SAXException {
- super.endDocument();
- }
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
- super.endElement(uri, localName, qName);
- if (!"config".equals(localName)) { // "config" 是根元素
- String key = localName;
- String value = accumulator.toString();
- result.put(key, value);
- }
- }
- public void startDocument() throws SAXException {
- super.startDocument();
- accumulator = new StringBuffer();
- result = new HashMap<String, String>();
- }
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- accumulator.setLength(0);
- }
- public HashMap<String, String> getResult() {
- return result;
- }
- }
- }
![](https://code.csdn.net/assets/CODE_ico.png)
- package com.suntek.mobilemeeting.interfaces;
- import com.suntek.mobilemeeting.config.ConfigController;
- /**
- * 常量类
- *
- * @author wwj
- *
- */
- public interface Const {
- String TEL_MOBILE = ConfigController.getInstance().get("TEL_MOBILE"); // 移动的号码段
- String TEL_UNICOM = ConfigController.getInstance().get("TEL_UNICOM"); // 联通的号码段
- String TELECOM = ConfigController.getInstance().get("TELECOM"); // 电信的号码段
- }
![](https://code.csdn.net/assets/CODE_ico.png)
- /**
- * <pre>
- * Const为常量类或接口
- * String TEL_MOBILE = config.get("TEL_MOBILE", "134,135,136,137,138,139,147,150,151,152,157,158,159,182,183,184,187,188"); //移动的号码段
- * String TEL_UNICOM = config.get("TEL_UNICOM", "130,131,132,155,156,185,186,145,176"); //联通的号码段
- *
- * 截至2013年12月30日 三大运营商号码段
- * 移动:134,135,136,137,138,139,147,150,151,152,157,158,159,182,183,184,187,188
- * 联通:130,131,132,155,156,185,186,145,176
- * 电信:133,153,180,181,189,1700,177
- * </pre>
- *
- * @param tel
- * @return 运营商 (1=移动、2=联通)
- */
- public static byte getTelCompany(String tel) {
- String telHead = "";
- if (tel.substring(0, 4).equals("1700")) {
- telHead = tel.substring(0, 4);
- } else {
- telHead = tel.substring(0, 3);
- }
- if (isMobileUnicom(telHead, 1)) {
- return 1;
- }
- if (isMobileUnicom(telHead, 2)) {
- return 2;
- }
- if (isMobileUnicom(telHead, 3)) {
- return 3;
- }
- return -1;
- }
- /**
- * 判断是哪种类型号码段
- *
- * @param telHead
- * @param company
- * @return
- */
- private static boolean isMobileUnicom(String telHead, int company) {
- String tel = "";
- switch (company) {
- case 1: // 移动号码段
- tel = Const.TEL_MOBILE;
- break;
- case 2: // 联通号码段
- tel = Const.TEL_UNICOM;
- break;
- case 3: // 电信号码段
- tel = Const.TELECOM;
- break;
- default:
- return false;
- }
- // 分割
- String[] aTel = tel.split(",");
- int iCount = aTel.length;
- for (int i = 0; i < iCount; i++) {
- if (aTel[i].equals(telHead)) {
- return true;
- }
- }
- return false;
- }
Android通讯录开发之获取运营商号码段(移动、联通、电信)相关推荐
- Android通讯录开发之获取运营商号码段(移动、联通,微信小程序的事件处理
<TEL_UNICOM> 130,131,132,155,156,185,186,145,176 </TEL_UNICOM> 133,153,180,181,189,1700, ...
- Android通讯录开发之获取运营商号码段(移动、联通,android选择题题库
133,153,180,181,189,1700,177 写一个配置文件控制器 package com.suntek.mobilemeeting.config; import java.io.Inpu ...
- android关闭应用及获取运营商ISP,判断sim卡属于哪个运营商
android关闭应用及获取运营商ISP 1.AndroidManifest.xml <?xml version="1.0" encoding="utf-8&quo ...
- 三大电信运营商号码段
为什么80%的码农都做不了架构师?>>> 最新三大电信运营商号码段部分: 中国移动号段 134.135.136.137.138.139. 147.150.151.152.157 ...
- Android软件开发之获取通讯录联系人信息
点击打开链接http://blog.csdn.net/snwrking/article/details/7601794 Android软件开发之获取通讯录联系人信息 + android联系人信息的存储 ...
- android获取各运营商信号,一篇关于 Android 获取运营商的全面笔记
发表时间:2019-10-20 内容总览 本文会给出在 Android 上获取运营商的方法,几个相近方法结果的差异,以及在多卡情况下有效的获取方式.最后额外提一下一种不需要请求设备识别码获取运营商信息 ...
- php 判断联通移动电信,JavaScript_JavaScript判断手机号运营商是移动、联通、电信还是其他(代码简单),正则表达式判断所填入号码的 - phpStudy...
JavaScript判断手机号运营商是移动.联通.电信还是其他(代码简单) 正则表达式判断所填入号码的运营商js代码修改版:/article/31563.htm 在做WEB项目时,有时候需要根据用户的 ...
- Android通讯录模糊匹配搜索实现(号码、首字母、简拼、全拼)
Android通讯录模糊匹配搜索实现(号码.首字母.简拼.全拼) 2013年12月10日 工作记录 小巫在工作中碰到一个需求,要求实现通讯录联系人的搜索,获取联系人的方式有好几种,我都有点混乱了,下面 ...
- Android通讯录模糊匹配搜索实现(号码 首字母 简拼 全拼)
Android通讯录模糊匹配搜索实现(号码.首字母.简拼.全拼) 2013年12月10日 工作记录 小巫在工作中碰到一个需求,要求实现通讯录联系人的搜索,获取联系人的方式有好几种,我都有点混乱了,下面 ...
最新文章
- G - MPI Maelstrom POJ - 1502
- 智能驾驶是否会“运动式”发展
- MySQL高效分页解决方案集
- 人生第一次手术:0806
- android中shape的属性,android中shape的属性
- python朋友圈切图代码
- 【转载】最好女孩子概率模型
- 第一章:Understanding web performance-理解web性能
- bash 命令提示符_命令行上每天的Bash提示
- 原有磁盘上创建lvm_Centos7创建LVM磁盘管理
- 创建Win2003域和Win2008域之间的信任关系,Active Directory系列之十八
- 华为服务器修改登录密码,服务器登录修改密码
- MySQL数据库之分库分表方案
- 大学生身价不如农民工,中国高等教育是否出了什么问题?
- 基于FBX SDK的FBX模型解析与加载 -(四)
- 【机器学习】十大机器学习基础算法
- IAR中使用IELFTOOL进行软件代码checksum的生成和添加
- VUE.JS 实现图片随鼠标变换的动画效果
- 公纵号发送提示信息(用户微服务--消息微服务)
- 把阿拉伯数字翻译成中文大写数字