Android 获取SIM卡运营商 .
来源:互联网 发布:制作蹭饭地图软件 编辑:程序博客网 时间:2024/05/17 07:13
在文件AndroidManifest.xml中添加权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
第一种方法:
获取手机的IMSI码,并判断是中国移动\中国联通\中国电信
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
/** 获取SIM卡的IMSI码
* SIM卡唯一标识:IMSI 国际移动用户识别码(IMSI:International Mobile Subscriber Identification Number)是区别移动用户的标志,
* 储存在SIM卡中,可用于区别移动用户的有效信息。IMSI由MCC、MNC、MSIN组成,其中MCC为移动国家号码,由3位数字组成,
* 唯一地识别移动客户所属的国家,我国为460;MNC为网络id,由2位数字组成,
* 用于识别移动客户所归属的移动网络,中国移动为00,中国联通为01,中国电信为03;MSIN为移动客户识别码,采用等长11位数字构成。
* 唯一地识别国内GSM移动通信网中移动客户。所以要区分是移动还是联通,只需取得SIM卡中的MNC字段即可
*/
String imsi = telManager.getSubscriberId();
if(imsi!=null){
if(imsi.startsWith("46000") || imsi.startsWith("46002")){//因为移动网络编号46000下的IMSI已经用完,所以虚拟了一个46002编号,134/159号段使用了此编号
//中国移动
}else if(imsi.startsWith("46001")){
//中国联通
}else if(imsi.startsWith("46003")){
//中国电信
}
}
第二种方法
TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String operator = telManager.getSimOperator();
if(operator!=null){
if(operator.equals("46000") || operator.equals("46002")){
//中国移动
}else if(operator.equals("46001")){
//中国联通
}else if(operator.equals("46003")){
//中国电信
}
}
示例代码:
package cn.itcast.getoperator;import android.app.Activity;import android.os.Bundle;import android.telephony.TelephonyManager;import android.view.View;import android.widget.Toast;public class DemoActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);}public void click(View view) {TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);String imsi = manager.getSubscriberId();// 下面的不一定可以成功// String imsi = manager.getSimOperator();if (imsi != null) {if (imsi.startsWith("46000") || imsi.startsWith("46002")) {// 因为移动网络编号46000下的IMSI已经用完,所以虚拟了一个46002编号,134/159号段使用了此编号// 中国移动Toast.makeText(getApplicationContext(), "中国移动", 1).show();} else if (imsi.startsWith("46001")) {// 中国联通Toast.makeText(getApplicationContext(), "中国联通", 1).show();} else if (imsi.startsWith("46003")) {// 中国电信Toast.makeText(getApplicationContext(), "中国电信", 1).show();}} else {Toast.makeText(getApplicationContext(), "获取失败", 1).show();}}}
- Android 获取SIM卡运营商
- Android 获取SIM卡运营商 .
- android 获取sim卡运营商信息
- android 获取sim卡运营商信息(转)
- android 获取sim卡运营商信息
- android 获取sim卡运营商信息(转)
- Android 获取手机SIM卡运营商
- android 获取sim卡运营商信息
- android 获取sim卡运营商信息(转)
- android 获取sim卡运营商信息
- 获取sim卡运营商
- Sim 卡运营商获取
- SIM 卡获取运营商信息
- android 获取sim卡运营商信息 .
- 安全退出应用+ 获取sim卡运营商
- 根据手机sim卡获取运营商信息
- Android判断SIM卡属于哪个移动运营商
- Android 判断SIM卡属于哪个移动运营商
- android ,点击title的ImageView弹出PopupWindow
- Nutch-2.2.1----过滤抓取数据
- Android中如何使用ViewPager实现类似laucher左右拖动效果
- 超级新手第一次修饰代码 不知道规范吗?请高手评价,谢谢了,
- ibatis typeHandler setparmeter list处理
- Android 获取SIM卡运营商 .
- 洗牌算法
- SQL字符串检索关键是和符号 LIKE, ESCAPE, ILIKE, ~, ~*, !~, !~* 的含义和区别
- android studio中使用第三方工程
- Re-installation failed due to different application signatures.
- Java泛型
- leetcode之Flatten Binary Tree to Linked List
- 单例模式
- 档案部门要做服务群众的一线部门