我写短信应用程序。这个应用程序在数据库中添加联系人,当收到短信时,它会在收件箱中删除并添加到我的数据库中,
我的代码:
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
db_contact = new DatabaseContact(context);
db_sms = new DatabaseSMS(context);
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "", str2 = "";
if (bundle != null) {
// ---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
str = msgs[i].getMessageBody().toString();
str2 = msgs[i].getOriginatingAddress();
}
// ---display the new SMS message---
Log.e("", str2);
db = db_contact.getReadableDatabase();
Cursor cursors = db.rawQuery("select * from " + db_contact.TABLE
+ " where tel='" + str2 + "' ", null);
for (int i = 0; i < cursors.getCount(); i++) {
cursors.moveToNext();
String name = cursors.getString(cursors.getColumnIndex("name"));
String tel = cursors.getString(cursors.getColumnIndex("tel"));
Log.e("Add to database : ", name + " ,tel " + tel);
db_sms.AddRow(name, tel, str);
Uri uriSms = Uri.parse("content://sms");
Cursor c = context.getContentResolver().query(uriSms, null,
null, null, null);
if (c.moveToNext()) {
int id = c.getInt(0);
int thread_id = c.getInt(1); // get the thread_id
context.getContentResolver().delete(
Uri.parse("content://sms/conversations/"
+ thread_id), null, null);
}
}
}
}
如何删除接收短信中的通知?如何在应用中管理通知?
谢谢