[程式問題]使用sqlite做簡訊攔截

2013.10.15 02:21PM

小妹現有一已建立之SQLITE 資料庫SMS TABLE名LIST 欄位_text1存各號碼

想用此來配合簡訊攔截做比對

 
 
 
public class SMS extends Activity {
 
private static final String DBNAME = "SMS";
    private static final String TABLENAME = "LIST";
    private static final String FIELD01_NAME = "_id";
    private static final String FIELD02_NAME = "_text1";
    private SQLiteDatabase db;
    private Cursor myCursor;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    
    db = this.openOrCreateDatabase(DBNAME, MODE_APPEND, null);
     
     String CREATE_SQL = "Create table if not exists " +
         TABLENAME + " (" + FIELD01_NAME +
         " integer primary key autoincrement, " +
         FIELD02_NAME + " varchar not null);";
     db.execSQL(CREATE_SQL);
     myCursor = db.query(TABLENAME,
             null, null, null, null, null, null);
     
  
 
}
 
 
private BroadcastReceiver mBroadcast =  new BroadcastReceiver() {
 
 
    @Override
     public void onReceive(Context context, Intent intent) {
 
         // 系統廣播MSG;
         if (intent.getAction()
                 .equals("android.provider.Telephony.SMS_RECEIVED")) {
             
             this.abortBroadcast();//不往下廣播
             StringBuffer sb = new StringBuffer();
             String sender = null;
             String content = null;
             String sendtime = null;
             Bundle bundle = intent.getExtras();
             if (bundle != null) {
                 Object[] pdus = (Object[]) bundle.get("pdus");
                 SmsMessage[] mges = new SmsMessage[pdus.length];
                 for (int i = 0; i < pdus.length; i++) {
                     mges[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                 }
                 for (SmsMessage mge : mges) {
                    sb.append("來自:" + mge.getDisplayOriginatingAddress()
                            + "\n");
                    sb.append("内容:" + mge.getMessageBody());
 
                    sender = mge.getDisplayOriginatingAddress();// 獲取發送者
                     content = mge.getMessageBody();// 獲取内容
                     Date date = new Date(mge.getTimestampMillis());
                    SimpleDateFormat format = new SimpleDateFormat(
                            "yyyy-MM-dd HH:mm:ss");
                    sendtime = format.format(date);// 獲取發送時間;
      
                    if (sender.equals( myCursor)) {  
                    
                     abortBroadcast(); // 終止BROADCAST  
                 
              }                    Toast.makeText(context, sb.toString(), Toast.LENGTH_LONG)
                         .show();        }
 
 
   }
 
}
};
}
 
 
可是在接受簡訊時便當掉並結束;
有請各神人大大指導是哪裡出了問題應該怎麼改嗎?!@@
 

相關消息

新品資訊
全新高效能筆電與掌機亮相!MSI 打造《龍魂城解鎖行動》實境互動體驗、週末限時登場等你來挑戰!
癮特務
2 天前
新奇搞笑
美國研發將核廢料轉化成再生能源的新技術
Twelve
2 天前
Xbox Game「Lips」Model
stoneip
16 年前
新品資訊
Intel 於中國 Bilibili World 活動上 宣布推出全新「AI 高靜遊戲筆電」概念設計
Mash Yang
23 個小時前
新品資訊
華碩 ROG x 初音未來聯名系列正式亮相
Mash Yang
1 天前
快訊
樂維 RK 藍牙無線機械鍵盤只要 2290,CP 未免也太高
Shopping guide
1 個月前
應用教學
2025城鎮韌性防空演習懶人包:日期時間、捷運高鐵台鐵乘車規定、人車交通管制 違規罰多少錢?
Zero圈圈
2 天前
快訊
左撇子福音來了!Logitech LIFT Left 垂直滑鼠,終於有人記得你用左手
Shopping guide
1 天前
遊戲天堂
《Monster Hunter Now》與富邦悍將跨界合作 夏日狩獵2025【海濱假期】全球同步展開
Mash Yang
23 個小時前