作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
Android手机发短信时,可以选择多个联系人(见A.png),短信会作为一条记录。
可以使用“content://sms/”查询短信吗? “地址”字段会返回多个电话号码吗?
谢谢!
A.png
public static List<String> ListDeleteOld(Context myContext, SMSRange mSMSRange, int beforeDays ) {
List<String> mListSmsID=new ArrayList<String>();
Uri uri=PublicParFun.GetUriBySMSRange(mSMSRange);
Date beforeDate=getCurrentBefore(beforeDays);
String[] projection = new String[] {"_id","address"};
Cursor cur = myContext.getContentResolver().query(uri, projection, "date<=" + beforeDate.getTime(), null, "date desc");
while(cur.moveToNext()){
String s=cur.getString(cur.getColumnIndex("address"));
}
cur.close();
return mListSmsID;
}
public static Uri GetUriBySMSRange(SMSRange mSMSRange){
Uri uri=null;
final String SMS_URI_ALL = "content://sms/";
final String SMS_URI_INBOX = "content://sms/inbox";
final String SMS_URI_SEND = "content://sms/sent";
final String SMS_URI_OUTBOX = "content://sms/outbox";
final String SMS_URI_DRAFT = "content://sms/draft";
switch (mSMSRange){
case All:
uri = Uri.parse(SMS_URI_ALL);
break;
case Inbox:
uri = Uri.parse(SMS_URI_INBOX);
break;
case Sentbox:
uri = Uri.parse(SMS_URI_SEND);
break;
case Outbox:
uri = Uri.parse(SMS_URI_OUTBOX);
break;
case Draft:
uri = Uri.parse(SMS_URI_DRAFT);
break;
}
return uri;
}
最佳答案
例如设置变量:
private static final Uri SMS_SENT_URI = Uri.parse("content://sms/sent");
private static final String SMS_ORDER = "date DESC";
private static final String ADDRESS_COLUMN_NAME = "address";
private static final String DATE_COLUMN_NAME = "date";
private static final String BODY_COLUMN_NAME = "body";
private static final String TYPE_COLUMN_NAME = "type";
private static final String ID_COLUMN_NAME = "_id";
private static final String SMS_PREFERENCES = "SMS_PREFERENCES";
您必须创建 SmsObject。然后通过 Cursor 循环。
整个代码:(调用 checkNewOutgoingSms(context))
private void checkNewOutgoingSms(Context context) {
Cursor smsCursor = getSmsCursor(context);
List<Sms> smsList = getLastSmsList(smsCursor,context);
if (smsList != null && smsList.size() > 0) {
ProtectorWSODao mwtProtectorDao = new ProtectorWSODao();
for (Sms sms : smsList) {
//
//
//read sms content
//
//
}
Manager.getInstance(context).sendDataToServer(mwtProtectorDao);
}
smsCursor.close();
}
public static Cursor getSmsCursor(Context context) {
return context.getContentResolver().query(SMS_SENT_URI, null, null, null, SMS_ORDER);
}
private List<Sms> getLastSmsList(Cursor smsCursor, Context context) {
List<Sms> smsList = new ArrayList<Sms>();
final int lastSmsIntercepted = smsStorage.getLastSmsIntercepted();
boolean update = false;
if (smsCursor != null) {
if (smsCursor.moveToFirst()) {
do {
Sms smsParsed = parseSms(smsCursor, context);
smsList.add(smsParsed);
} while (smsCursor.moveToNext());
}
}
return smsList;
}
public static Sms parseSms(Cursor cursor, Context context) {
String number = cursor.getString(cursor.getColumnIndex(ADDRESS_COLUMN_NAME));
String date = cursor.getString(cursor.getColumnIndex(DATE_COLUMN_NAME));
String content = cursor.getString(cursor.getColumnIndex(BODY_COLUMN_NAME));
int smsId = cursor.getInt(cursor.getColumnIndex(ID_COLUMN_NAME));
return new Sms(Sms.SEND, smsId, number, date, content);
}
关于android - 一次给多个电话号码发短信,地址栏会存储多个电话号码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31175008/
我是一名优秀的程序员,十分优秀!