private class getItemLists extends AsyncTask<Void, String, String> {
private Context mContext;
public getItemLists(Context context) {
mContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
ld.setVisibility(View.VISIBLE);
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
// Intent i = new Intent("notify.intent.MAIN");
// mContext.sendBroadcast(i);
}
@Override
protected String doInBackground(Void... params) {
try {
Chatdb db = new Chatdb(mContext);
String[] smsid = db.getAllinboxsmsid();
// Create Inbox box URI
Uri inboxURI = Uri.parse("content://sms/inbox");
// List required columns
String[] reqCols = new String[] { "_id", "address", "body",
"date", "read" };
// Get Content Resolver object, which will deal with Content
// Provider
ContentResolver cr = mContext.getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor c = cr.query(inboxURI, reqCols, null, null, null);
boolean exists = false;
if (c.moveToLast()) {
do {
exists = false;
publishProgress((c.getCount() - c.getPosition() + ";" + c
.getCount()));
for (int x = 0; x < smsid.length; x++) {
if (smsid[x].equals(c.getString(0))) {
exists = true;
}
}
if (!exists) {
if (c.getString(4).equals("0")) {
smsRead = "1";
} else {
smsRead = "0";
}
db.addMsgWithTime(c.getString(1), c.getString(2),
"1", "0", "L", c.getString(0),
c.getString(3), smsRead);
publishProgress((c.getCount() - c.getPosition()
+ ";" + c.getCount()));
// Intent in = new
// Intent("SmsMessage.intent.MAIN").putExtra(
// "get_msg", c.getString(1));
//
// // You can place your check conditions here(on
// the SMS or the
// // sender)
// // and then send another broadcast
// SuperMain.this.sendBroadcast(in);
}
} while (c.moveToPrevious());
}
// c.close();
//
String[] SentSmsId = db.getAllsentsmsid();
Uri sentURI = Uri.parse("content://sms/sent");
// List required columns
String[] reqColsSent = new String[] { "_id", "address", "body",
"date", "read" };
// Get Content Resolver object, which will deal with Content
// Provider
// Fetch Inbox SMS Message from Built-in Content Provider
c = cr.query(sentURI, reqColsSent, null, null, null);
if (c.moveToLast()) {
do {
exists = false;
publishProgress((c.getCount() - c.getPosition() + ";" + c
.getCount()));
for (int x = 0; x < SentSmsId.length; x++) {
if (SentSmsId[x].equals(c.getString(0))) {
exists = true;
}
}
if (!exists) {
db.addMsgWithTime(c.getString(1), c.getString(2),
"0", "0", "S", c.getString(0),
c.getString(3), "1");
// db.close();
publishProgress((c.getCount() - c.getPosition()
+ ";" + c.getCount()));
}
} while (c.moveToPrevious());
}
c.close();
db.close();
} catch (Exception e) {
Log.d("ERROR", e.toString());
}
return "done";
}
@Override
protected void onPostExecute(String done) {
super.onPostExecute(done);
// Toast.makeText(mContext, "Messages have synced successfully",
// 3).show();
ld.setVisibility(View.INVISIBLE);
}
}
这是收件箱和已发送邮件的加载程序,并显示在mu list视图中。 这里ld是我的加载器......显示何时加载数据
public String[] getAllsentsmsid() {
String selectQuery = "SELECT " + KEY_SMSID + " FROM " + TABLE_THREAD
+ " WHERE " + KEY_SMSID + "<>'0' AND " + KEY_ORIGIN + "='0'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
String[] allid = new String[cursor.getCount()];
int x = 0;
if (cursor.moveToFirst()) {
do {
allid[x] = cursor.getString(0);
x++;
} while (cursor.moveToNext());
}
db.close();
return allid;
}
public String[] getAllinboxsmsid() {
String selectQuery = "SELECT " + KEY_SMSID + " FROM " + TABLE_THREAD
+ " WHERE " + KEY_SMSID + "<>'0' AND " + KEY_ORIGIN + "='1'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
String[] allid = new String[cursor.getCount()];
int x = 0;
if (cursor.moveToFirst()) {
do {
allid[x] = cursor.getString(0);
x++;
} while (cursor.moveToNext());
}
db.close();
return allid;
}
这些是我的数据库方法,我存储消息id并将其保存在我的数据库中。
在我的列表视图中制作重复的聊天主题。