}
=================================== 分割 ==================================
之前封装的不够好,现在改版下!
package com.meiya.util;
import java.util.UUID;
import android.content.Context;
import android.provider.Settings.System;
import android.telephony.TelephonyManager;
/**
*
* @Description: 获取手机相关
* @File: SimUtil.java
* @Paceage com.meiya.util
* @Author huangxj
* @Date 上午9:47:25
* @Version
*/
public class SimUtil {
public static final String TAG = "SimUtil";
private static TelephonyManager tmManager;
private static SimUtil instance = null;
private SimUtil(){
}
public static SimUtil getInstance(Context mContext){
if(instance == null){
instance = new SimUtil();
}
instance.setTelephonyManager(mContext);
instance.printInfo();
return instance;
}
private void setTelephonyManager(Context context){
tmManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
}
/**获取imsi信息
* @param context
*/
public String getSubcribId(){
try {
return tmManager.getSubscriberId();
} catch (Exception e) {
return null;
}
}
/**获取sim手机号码
* @param context
*/
public String getSimNumber(){
try {
return tmManager.getLine1Number();
} catch (Exception e) {
return null;
}
}
/**获取设备ID
* @param context
*/
public String getDeviceId(){
try {
return tmManager.getDeviceId();
} catch (Exception e) {
return null;
}
}
/**获取设备运营商名称
* @param context
*/
public String getSimOperatorName(){
try {
return tmManager.getSimOperatorName();
} catch (Exception e) {
return null;
}
}
/**返回运营商编号
* @param context
*/
public int getOperator(){
String imsi = getSubcribId();
if(imsi!=null){
if(imsi.startsWith("46000") || imsi.startsWith("46002"))
{ //因为移动网络编号46000下的IMSI已经用完,所以虚拟了一个46002编号,134/159号段使用了此编号
//中国移动
return 0;
}else if(imsi.startsWith("46001")){
//中国联通
return 1;
}else if(imsi.startsWith("46003")){
//中国电信
return 2;
}
}
return -1;
}
/**
* 获取设备的唯一识别码 UUID
* @return
*/
public String getUUID(){
String tmDevice, tmSerial, tmPhone, androidId;
tmDevice = "" + getDeviceId();
Logger.log(TAG + "tmDevice = " + tmDevice);
UUID deviceUuid = new UUID(tmDevice.hashCode(), (long)tmDevice.hashCode() << 32);
String uniqueId = deviceUuid.toString();
return uniqueId;
}
private void printInfo(){
Logger.log(TAG + "DeviceID = " + getDeviceId() + " phoneNumber = "+getSimNumber() +" imsi = "+ getSubcribId() +" operator = "+ getSimOperatorName());
}
}