Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I did it like the following. Create SMSObject:</p> <pre><code>public class SMSObject { private String _id; private String _address; private String _msg; private String _readState; // "0" for have not read sms and "1" for have // read sms private String _time; private String _folderName; //+ getter and setter methods and @Override public String toString() { return "SMSObject [_id=" + _id + ", _address=" + _address + ", _msg=" + _msg + ", _readState=" + _readState + ", _time=" + _time + ", _folderName=" + _folderName + "]"; } </code></pre> <p>And here a simple function, which simply logs all current SMS-Objects</p> <pre><code>private void readSMS() { List&lt;SMSObject&gt; lstSms = new ArrayList&lt;SMSObject&gt;(); SMSObject objSms = new SMSObject(); Uri message = Uri.parse("content://sms/"); ContentResolver cr = this.getContentResolver(); Cursor c = cr.query(message, null, null, null, null); // this.startManagingCursor(c); int totalSMS = c.getCount(); Log.d("SMS Count-&gt;", "" + totalSMS); if (c.moveToFirst()) { for (int i = 0; i &lt; totalSMS; i++) { objSms = new SMSObject(); objSms.setId(c.getString(c.getColumnIndexOrThrow("_id"))); objSms.setAddress(c.getString(c .getColumnIndexOrThrow("address"))); objSms.setMsg(c.getString(c.getColumnIndexOrThrow("body"))); objSms.setReadState(c.getString(c.getColumnIndex("read"))); objSms.setTime(c.getString(c.getColumnIndexOrThrow("date"))); if (c.getString(c.getColumnIndexOrThrow("type")).contains("1")) { objSms.setFolderName("inbox"); } else { objSms.setFolderName("sent"); } lstSms.add(objSms); Log.d("SMS at " + i, objSms.toString()); c.moveToNext(); } } // else { // throw new RuntimeException("You have no SMS"); // } c.close(); // return lstSms; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload