How to detect outgoing SMS messages in the backgound of an Android application?
How can I run an Android application in the background that counts the number of SMS messages sent and, in addition, determine the deta开发者_高级运维il of each one?
you can fetch sent msg:
Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri,
new String[] { "_id", "thread_id", "address", "person", "date",
"body", "type" }, null, null, null);
startManagingCursor(cursor1);
String[] columns = new String[] { "address", "person", "date", "body","type" };
if (cursor1.getCount() > 0) {
String count = Integer.toString(cursor1.getCount());
Log.e("Count",count);
while (cursor1.moveToNext()){
String address = cursor1.getString(cursor1.getColumnIndex(columns[0]));
String name = cursor1.getString(cursor1.getColumnIndex(columns[1]));
String date = cursor1.getString(cursor1.getColumnIndex(columns[2]));
String msg = cursor1.getString(cursor1.getColumnIndex(columns[3]));
String type = cursor1.getString(cursor1.getColumnIndex(columns[4]));
}
}
you can use counter to retrive recently sent sms.
See other useful links:
Android: Is there any way to listen outgoing sms?
Listen outgoing SMS or sent box in Android
How to listen/subscribe to Outgoing SMS notifications?
精彩评论