상세 컨텐츠

본문 제목

문자 메시지 스팸 리스트 가져오기.

Android.. Story

by HeyLee 2016. 4. 18. 15:34

본문

public void SMSList() {  

   try {  

       // Retrieve All SMS  

       /* 

           Inbox = "content://sms/inbox" 

           Failed = "content://sms/failed"  

           Queued = "content://sms/queued"  

           Sent = "content://sms/sent"  

           Draft = "content://sms/draft" 

           Outbox = "content://sms/outbox" 

           Undelivered = "content://sms/undelivered" 

           All = "content://sms/all" 

           Conversations = "content://sms/conversations" 

 

           addressCol= mCurSms.getColumnIndex("address");  

           personCol= mCurSms.getColumnIndex("person");  

           dateCol = mCurSms.getColumnIndex("date");  

           protocolCol= mCurSms.getColumnIndex("protocol");  

           readCol = mCurSms.getColumnIndex("read");  

           statusCol = mCurSms.getColumnIndex("status");  

           typeCol = mCurSms.getColumnIndex("type");  

           subjectCol = mCurSms.getColumnIndex("subject");  

           bodyCol = mCurSms.getColumnIndex("body"); 

        */  

       Uri allMessage = Uri.parse("content://mms-sms/spam-filter");    

       Cursor cur = this.getContentResolver().query(allMessage, null, null, null, null);  

       int  count = cur.getCount();  

       for(int i=0;i<count;i++){

        Log.i("heylee" , "SMS count = " + count+" "+cur.getColumnName(i));

       }

//        04-18 15:26:49.844: I/heylee(17536): SMS count = 4 enable

//         04-18 15:26:49.844: I/heylee(17536): SMS count = 4 filter


//        04-18 15:25:07.684: I/heylee(16355): SMS count = 2 filter_type


       String row = "";  

       String msg = "";  

       String date = "";  

       String protocol = "";  

       while (cur.moveToNext()) {  

           row = cur.getString(cur.getColumnIndex("_id"));  //등록된 순서 대로 ... 부여되는 id  1,2,3,4,....

           msg = cur.getString(cur.getColumnIndex("filter_type"));  //이게 0이면 스팸 번호, 1이면 스팸문구.

           date = cur.getString(cur.getColumnIndex("enable"));  

           protocol = cur.getString(cur.getColumnIndex("filter"));  // 번호 or스팸 문

           // Logger.d( TAG , "SMS PROTOCOL = " + protocol);    

             

//            String type = "";  

//            if (protocol == MESSAGE_TYPE_SENT) type = "sent";  

//            else if (protocol == MESSAGE_TYPE_INBOX) type = "receive";  

//            else if (protocol == MESSAGE_TYPE_CONVERSATIONS) type = "conversations";   

//            else if (protocol == null) type = "send";   

 

           Log.i( "heylee" , "SMS Phone: " + row + " / Mesg: " + msg + " / Type: " + date + " / Date: " + protocol);  

       }  

   } catch (Exception e) {  

       e.printStackTrace();  

   }  

}


  1. public void SMSDelete() {  
  2.     Uri deleteUri = Uri.parse("content://sms");  
  3.     int count = 0;  
  4.     Cursor c = this.getContentResolver().query(deleteUri, nullnull,  
  5.             nullnull);  
  6.     while (c.moveToNext()) {  
  7.         try {  
  8.             // Delete the SMS  
  9.             String pid = c.getString(0);  
  10.             // Get id;  
  11.             String uri = "content://sms/" + pid;  
  12.             // count = this.getContentResolver().delete(Uri.parse(uri),null, null);  
  13.         } catch (Exception e) {  
  14.         }  
  15.     }  
  16. }  


관련글 더보기

댓글 영역