HashSet set = new HashSet ();
try {
ContentResolver cr = getContentResolver ();
String [] exct = new String [] {"_id", "thread_id", "address", "person",
"Body", "date", "type"};
Uri uri = Uri.parse (SMS_URI_ALL);
Cursor cursor = cr.query (uri, exct, null, null, "date desc");
if (cursor.moveToNext ()) {
Cursor cur = cr.query (uri, exct, null, null, "date desc");
while (cur.moveToNext ()) {
sms = new Sms ();
sms.setPersion (cur.getString (3));
sms.setAddress ((cur.getString (2)));
sms.setBody (cur.getString (4));
sms.setThread_id (cur.getString (1));
SimpleDateFormat dateFormat = new SimpleDateFormat ("MM-dd");
Date date = new Date (Long.parseLong (cur.getString (5)));
sms.setDate (dateFormat.format (date));
SimpleDateFormat datetimeFormat = new SimpleDateFormat ("hh: mm");
Date datetime = new Date (Long.parseLong (cur.getString (5)));
sms.setDatetime (datetimeFormat.format (datetime));
sms.setType (cur.getString (6));
if (set.add (sms.getThread_id ())) {
list.add (sms);
}
}
cur.close ();
}
The above is to get SMS code, for example, I send two messages, "1", "2", the first time send a "1" when calling this method reads the database, there is no value, but the database there. " 1 "value, the second sending" 2 "when calling this method, access to" 1 "this sms, but the database there are" 1 "," 2 "two values, solving this is why, I think it does not close cr thread can not refresh the cause, but do not know how to modify, seeking guidance,,,
Reply:
And if this method on the activity's onCreate method which can normally get when all the values, and on the radio inside, it will delay a message, which is why,,,
Reply:
Data may be due to one less moveToNext () with two
Reply:
certainly not the reason, because where moveToNext used twice,,,
Reply:
Great God solved,
Reply:
Reply:
Do not Shen Shen, seeking expert wrote a similar, posted under the demo,,,
Reply:
The landlord he could not top, friendship Bangding
Reply:
sms = new Sms (); What is
Reply:
cursor.moveToFirst () you do not go this one?
Reply:
It is not the default first?
Reply:
I suspect you do not operate the first
Reply:
I spent a morning time has finally checked out, because android is loaded asynchronously intercept short interest is 0.0017 seconds to execute code while performing insert messages into a database is 0.0023 seconds, so the database can not be checked, can only delay the query.
No comments:
Post a Comment