AndroidManifest.xml 에 퍼미션 추가

<uses-permission android:name="android.permission.READ_SMS" />
< uses-permission android:name="android.permission.WRITE_SMS" />

SMSList.java
public static final String MESSAGE_TYPE_INBOX = "1";
public static final String MESSAGE_TYPE_SENT = "2";
public static final String MESSAGE_TYPE_CONVERSATIONS = "3";
public static final String MESSAGE_TYPE_NEW = "new";

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://sms/");
cur = this.getContentResolver().query(allMessage, null, null, null, null);
count = cur.getCount();
Logger.i( TAG , "SMS count = " + count);
String row = "";
String msg = "";
String date = "";
String protocol = "";
while (cur.moveToNext()) {
row = cur.getString(cur.getColumnIndex("address"));
msg = cur.getString(cur.getColumnIndex("body"));
date = cur.getString(cur.getColumnIndex("date"));
protocol = cur.getString(cur.getColumnIndex("protocol"));
// 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";

Logger.i( TAG , "SMS Phone: " + row + " / Mesg: " + msg + " / Type: " + type + " / Date: " + date);
}
} catch (IOException e) {
e.printStackTrace();
}
}

public void SMSDelete() {
Uri deleteUri = Uri.parse("content://sms");
int count = 0;
Cursor c = this.getContentResolver().query(deleteUri, null, null,
null, null);
while (c.moveToNext()) {
try {
// Delete the SMS
String pid = c.getString(0);
// Get id;
String uri = "content://sms/" + pid;
// count = this.getContentResolver().delete(Uri.parse(uri),null, null);
} catch (Exception e) {
}
}
}

참고사이트)
http://blog.naver.com/algorithmlab?Redirect=Log&logNo=70098254191
http://mobdev.olin.edu/mobdevwiki/FrontPage/Tutorials/SMS%20Messaging#Catch_the_new_SMS_message
http://stackoverflow.com/questions/2584058/android-querying-the-sms-contentprovider
http://youropensource.com/projects/559-get-All-SMS-messages-in-the-Android
http://stackoverflow.com/questions/2183680/delete-sms-in-android-1-5
 

2011/12/06 11:34 2011/12/06 11:34

Trackback Address :: https://youngsam.net/trackback/1697