Android 5.0 双卡短信处理
1. 得到sim卡数量
private int simNum = 0;
private String simName[][] = new String[2][2];
public int getSimInfo() {
simNum = 0;
ContentResolver resolver = this.getContentResolver();
Uri uri = Uri.parse("content://telephony/siminfo");
final String[] PHONES_PROJECTION = new String[] { "sim_id",
"display_name", "mcc", "mnc" };
Cursor phoneCursor = resolver.query(uri, PHONES_PROJECTION, null, null,
null);
if (phoneCursor != null) {
while (phoneCursor.moveToNext()) {
int id = phoneCursor.getColumnIndex("sim_id");
String number = phoneCursor.getString(id);
Log.d("sim", "number" + number);
if (number.equals("0")) {
simNum++;
int id2 = phoneCursor.getColumnIndex("display_name");
String display_name = phoneCursor.getString(id2);
Log.d("sim", "display_name" + display_name);
simName[0][0] = display_name;
int id3 = phoneCursor.getColumnIndex("mcc");
String mcc = phoneCursor.getString(id3);
int id4 = phoneCursor.getColumnIndex("mnc");
String mnc = phoneCursor.getString(id4);
simName[0][1] = mcc + mnc;
Log.d("sim", simName[0][1]);
} else if (number.equals("1")) {
simNum++;
int id2 = phoneCursor.getColumnIndex("display_name");
String display_name = phoneCursor.getString(id2);
Log.d("sim", "display_name" + display_name);
simName[1][0] = display_name;
int id3 = phoneCursor.getColumnIndex("mcc");
String mcc = phoneCursor.getString(id3);
int id4 = phoneCursor.getColumnIndex("mnc");
String mnc = phoneCursor.getString(id4);
simName[1][1] = mcc + mnc;
Log.d("sim", simName[1][1]);
}
}
}
return simNum;
}
simNum=2 时才取simName中保存的卡信息
2. 根据sim卡信息查余额
private void sendSms(int i) {
String s = simName[i][1];
SmsManager smsManager = SmsManager.getDefault();
if ("4600".equals(s)) {
Toast.makeText(AlertActivity.this, "正在发送短信查询余额", Toast.LENGTH_SHORT)
.show();
smsManager.sendTextMessage("10086", null, "YE", null, null);
} else if ("4601".equals(s)) {
Toast.makeText(AlertActivity.this, "正在发送短信查询余额", Toast.LENGTH_SHORT)
.show();
smsManager.sendTextMessage("10010", null, "YE", null, null);
} else if ("4602".equals(s)) {
Toast.makeText(AlertActivity.this, "正在发送短信查询余额", Toast.LENGTH_SHORT)
.show();
smsManager.sendTextMessage("10001", null, "YE", null, null);
} else {
Toast.makeText(AlertActivity.this, "暂不支持此类Sim卡的余额查询",
Toast.LENGTH_SHORT).show();
}
}
3. 单卡处理
/** 返回手机服务商名字 */
public static String getProvidersName(Context context) {
String ProvidersName = null;
// 返回唯一的用户ID;就是这张卡的编号神马的
String imsi = getIMSI(context);
// IMSI号前面3位460是国家,紧接着后面2位00 02是中国移动,01是中国联通,03是中国电信。
if (imsi == null) {
ProvidersName = "其他服务商:" + imsi;
} else if (imsi.startsWith("46000") || imsi.startsWith("46002") || imsi.startsWith("46007")) {
ProvidersName = "中国移动";
} else if (imsi.startsWith("46001") || imsi.startsWith("46006")) {
ProvidersName = "中国联通";
} else if (imsi.startsWith("46003") || imsi.startsWith("46005")) {
ProvidersName = "中国电信";
} else {
ProvidersName = "其他服务商:" + imsi;
}
return ProvidersName;
}
String provider = getProvidersName(getApplicationContext());
SmsManager smsManager = SmsManager.getDefault();
if ("中国移动".equals(provider)) {
Toast.makeText(AlertActivity.this, "正在发送短信查询余额",
Toast.LENGTH_SHORT).show();
smsManager.sendTextMessage("10086", null, "YE", null,
null);
} else if ("中国联通".equals(provider)) {
Toast.makeText(AlertActivity.this, "正在发送短信查询余额",
Toast.LENGTH_SHORT).show();
smsManager.sendTextMessage("10010", null, "YE", null,
null);
} else if ("中国电信".equals(provider)) {
Toast.makeText(AlertActivity.this, "正在发送短信查询余额",
Toast.LENGTH_SHORT).show();
smsManager.sendTextMessage("10001", null, "YE", null,
null);
} else {
Toast.makeText(AlertActivity.this, "暂不支持此类Sim卡的
余额查询",Toast.LENGTH_SHORT).show();
}