我有这段代码,我读了关于短信的所有信息:
Uri mSmssentQueryUri = Uri.parse("content://sms/sent");
Cursor cursorS = getContentResolver().query(mSmssentQueryUri,null, null, null, null);
if (cursorS.getCount() > 0) {
while (cursorS.moveToNext()){
date = cursorS.getString(4);
address = cursorS.getString(2);
JSONObject jsonSms= new JSONObject();
jsonSms.put("type", "sms");
jsonSms.put("date", date);
jsonSms.put("receiver", address);
jsonSms.put("direction", "OUTGOING");
jsonObj.put("SMS"+date, jsonSms);
}
}
我对使用CallLog.calls的调用做了同样的事情,但是我可以找到更多的信息,例如countryIso,它可以为我提供用户收到或拨打电话的国家/地区的国家/地区代码。 当我发送短信时,有没有办法获得相同的信息,所以我可以读到短信是从国外寄来的?
答案 0 :(得分:0)
将地址字段值作为电话传递到以下功能
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
try {
// phone must begin with '+'
PhoneNumber numberProto = phoneUtil.parse(phone, "");
int countryCode = numberProto.getCountryCode();
} catch (NumberParseException e) {
System.err.println("NumberParseException was thrown: " + e.toString());
}