读取收件箱中的短信,然后读取短信中心号码,和手机设置中的短信中心号码比较不一致
private String readSmsCenter(Context context) {
String SMS_URI_INBOX = "content://sms/inbox";
String COLUMN_NAME_ID = "_id";
String COLUMN_NAME_PROTOCOL = "protocol";
String COLUMN_NAME_TYPE = "type";
String COLUMN_NAME_BODY = "body";
String COLUMN_NAME_SERVICE_CENTER = "service_center";
ContentResolver cr = context.getContentResolver();
Uri uri = Uri.parse(SMS_URI_INBOX);
Cursor cur = cr.query(uri, new String[] {
COLUMN_NAME_ID, COLUMN_NAME_PROTOCOL, COLUMN_NAME_TYPE, COLUMN_NAME_SERVICE_CENTER
}, null, null, "date desc");
if (cur == null) {
return null;
}
int nCount = cur.getCount();
int nProtocolColumn = 0;
int nTypeColumn = 0;
int nServiceCenterColumn = 0;
int nBodyColumn = 0;
int nProtocol;
int nType;
String serviceCenter = null;
cur.moveToFirst();
for (int i = 0; i < nCount; i++) {
nProtocolColumn = cur.getColumnIndex(COLUMN_NAME_PROTOCOL);
nTypeColumn = cur.getColumnIndex(COLUMN_NAME_TYPE);
nServiceCenterColumn = cur.getColumnIndex(COLUMN_NAME_SERVICE_CENTER);
nBodyColumn = cur.getColumnIndex(COLUMN_NAME_BODY);
serviceCenter = null;
nProtocol = cur.getInt(nProtocolColumn);
nType = cur.getInt(nTypeColumn);
if (nProtocol == 0 && nType == 1) {
serviceCenter = cur.getString(nServiceCenterColumn);
break;
}
cur.moveToPrevious();
}
cur.close();
return serviceCenter;
}
真机上测试,读出来的号码是+8613800311543,从手机设置中看到的号码是+8613800311500,两个不一样,而且+8613800311543这个号码好像也不是一个正确的短信中心号。
为什么直接读出来的不对呢?
296 阅读
不知道,我只玩过J2ME,
,看你的安卓怎么写得那么多,J2ME一句话足以