2013-08-25 44 views
1

我写短信application.this应用程序添加联系人数据库,并收到短信时,在收件箱中删除,并增加了我的数据库,如何删除通知,收到短信的Android

我的代码:

@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); 

     } 

    } 

} 
} 

如何在接收短信中删除通知? 如何在应用程序中管理通知?

感谢

回答

2

不是真的知道什么是这里的问题,但如果你任何机会想删除您的通知的话,好了,别在首位张贴英寸如果你想在其他应用程序中禁用,那么你只能告诉你的用户他们应该在其他应用程序的设置中禁用这些通知。

0

删除通知

通知保持可见,直到发生以下情况之一:

  • 用户退出通知单独或通过使用 “全部清除”(如果该通知可以被清除)。
  • 用户单击通知,并且当您创建通知时您调用setAutoCancel() 。
  • 您可以为特定通知ID调用cancel()。此方法还会删除正在进行的通知。
  • 您可以调用cancelAll(),它将删除您以前发出的所有通知 。