Package com.homer.sms;
Import Java.sql.Date;
Import Java.text.SimpleDateFormat;
Import android.app.Activity;
Import Android.database.Cursor;
Import android.database.sqlite.SQLiteException;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.widget.ScrollView;
Import Android.widget.TableLayout;
Import Android.widget.TextView;
public class Smsread extends activity {
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
TextView TV = new TextView (this);
Tv.settext (Getsmsinphone ());
ScrollView SV = new ScrollView (this);
Sv.addview (TV);
Setcontentview (SV);
}
Public String Getsmsinphone () {
Final String Sms_uri_all = "content://sms/";
Final String Sms_uri_inbox = "Content://sms/inbox";
Final String sms_uri_send = "Content://sms/sent";
Final String Sms_uri_draft = "Content://sms/draft";
Final String Sms_uri_outbox = "Content://sms/outbox";
Final String sms_uri_failed = "content://sms/failed";
Final String sms_uri_queued = "content://sms/queued";
StringBuilder Smsbuilder = new StringBuilder ();
try {
Uri uri = Uri.parse (Sms_uri_all);
string[] projection = new string[] {' _id ', ' address ', ' person ', ' body ', ' date ', ' type '};
Cursor cur = getcontentresolver (). Query (URI, projection, null, NULL, "date desc"); Get SMS inside Mobile phone
if (Cur.movetofirst ()) {
int index_address = Cur.getcolumnindex ("Address");
int Index_person = Cur.getcolumnindex ("person");
int index_body = Cur.getcolumnindex ("Body");
int index_date = Cur.getcolumnindex ("Date");
int index_type = Cur.getcolumnindex ("Type");
do {
String straddress = cur.getstring (index_address);
int Intperson = Cur.getint (Index_person);
String strbody = cur.getstring (index_body);
Long longdate = Cur.getlong (index_date);
int inttype = Cur.getint (Index_type);
SimpleDateFormat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd hh:mm:ss");
Date d = new Date (longdate);
String strdate = Dateformat.format (d);
String strtype = "";
if (inttype = = 1) {
Strtype = "Receive";
else if (Inttype = 2) {
strtype = "Send";
} else {
Strtype = "NULL";
}
Smsbuilder.append ("[");
Smsbuilder.append (straddress + ",");
Smsbuilder.append (Intperson + ",");
Smsbuilder.append (Strbody + ",");
Smsbuilder.append (strdate + ",");
Smsbuilder.append (strtype);
Smsbuilder.append ("]\n\n");
while (Cur.movetonext ());
if (!cur.isclosed ()) {
Cur.close ();
cur = null;
}
} else {
Smsbuilder.append ("no result!");
}//End If
Smsbuilder.append ("Getsmsinphone has executed!");
catch (Sqliteexception ex) {
LOG.D ("Sqliteexception in Getsmsinphone", Ex.getmessage ());
}
return smsbuilder.tostring ();
}
}
Remember to join Android.permission.READ_SMS this permission in Androidmanifest.xml.