package com.entel.readmessage; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.widget.TextView; public class ReadMessageActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView textView = (TextView)findViewById(R.id.text); Uri uri = Uri.parse("content://sms/"); String[] projection = new String[] { "_id", "address", "person", "body", "date", "type" }; Cursor cusor = managedQuery(uri, projection, null, null, "date desc"); int nameColumn = cusor.getColumnIndex("person"); int phoneNumberColumn = cusor.getColumnIndex("address"); int smsbodyColumn = cusor.getColumnIndex("body"); int dateColumn = cusor.getColumnIndex("date"); int typeColumn = cusor.getColumnIndex("type"); List<MessageInfor> infos = new ArrayList<MessageInfor>(); if (cusor != null) { while (cusor.moveToNext()) { MessageInfor smsinfo = new MessageInfor(); smsinfo.setName(cusor.getString(nameColumn)); smsinfo.setDate(cusor.getString(dateColumn)); smsinfo.setPhoneNumber(cusor.getString(phoneNumberColumn)); smsinfo.setSmsbody(cusor.getString(smsbodyColumn)); smsinfo.setType(cusor.getString(typeColumn)); infos.add(smsinfo); } cusor.close(); } String str = ""; for(int i = 0; i < infos.size(); i++) { str += infos.get(i).getSmsbody() + "\n"; } textView.setText(str); } }
package com.entel.readmessage; public class MessageInfor { private String smsbody; private String phoneNumber; private String date; private String name; private String type; public MessageInfor() { } public String getSmsbody() { return smsbody; } public void setSmsbody(String smsbody) { this.smsbody = smsbody; } public String getPhoneNumber() { return phoneNumber; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String type) { this.type = type; } }