2014-02-07 62 views

回答

2

使用此:

private String SmsDetails(Application mContext) { 
     // TODO Auto-generated method stub 
     smsInbox = new ArrayList<Entry>(); 

     final Uri SMS_Inbox = Uri.parse("content://sms/inbox"); 
     String smsHistory = ""; 

     try { 

      String sDirection = "1"; 
      String sMessageType = "0"; 
      String SMS_READ_COLUMN = "read"; 
      String SORT_ORDER = " _id ASC"; 
      int count = 0; 
      Cursor cursor; 
      int iLastIDRun = 0; 

      // "address = '+9180009'" 

      cursor = mContext.getContentResolver().query(
        SMS_Inbox, 
        new String[] { "_id", "thread_id", "address", "person", 
        "date", "body" }, 
        " _id > " + String.valueOf(iLastIDRun), null, 
        SORT_ORDER); 
      sMessageType = "1"; 
      if (cursor != null) { 
       try { 

        if (cursor.moveToFirst()) { 
         do { 
          String address = cursor.getString(2); 
          long timestamp = cursor.getLong(4); 
          String sBody = cursor.getString(5); 

          if (address.startsWith("1")) { 
           address = address.substring(1); 
          } 

          //store the required details 



         } while (cursor.moveToNext()); 

        } 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
       cursor.close(); 

      } 

      doCheckSmsHistory(); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return smsHistory; 

    } 
相關問題