- 论坛徽章:
- 0
|
1, Listen to incoming SMS
1.1, Prepare manifest file
Remark: action android.provider.Telephony.SMS_RECEIVED is undocumented.
1.2, Parse SMS
package org.apache.sms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
public class SMSApp extends BroadcastReceiver
{
private static final String LOG_TAG = "SMSApp";
/* package */
static final String ACTION =
"android.provider.Telephony.SMS_RECEIVED";
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(ACTION))
{
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Object[] pdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i String strUriInbox = "content://sms/inbox";//SMS_INBOX:1
String strUriFailed = "content://sms/failed";//SMS_FAILED:2
String strUriQueued = "content://sms/queued";//SMS_QUEUED:3
String strUriSent = "content://sms/sent";//SMS_SENT:4
String strUriDraft = "content://sms/draft";//SMS_DRAFT:5
String strUriOutbox = "content://sms/outbox";//SMS_OUTBOX:6
String strUriUndelivered =
"content://sms/undelivered";//SMS_UNDELIVERED
String strUriAll = "content://sms/all";//SMS_ALL
String strUriConversations = "content://sms/conversations";//you
can delete one conversation by thread_id
String strUriAll = "content://sms"//you can delete one message by _id
*/
String strUriInbox = "content://sms/inbox";
Uri uriSms = Uri.parse(strUriInbox); //If you want to access all SMS, just replace the uri string to "content://sms/"
Cursor c = mContext.getContentResolver().query(uriSms, null, null, null, null);
while (c.moveToNext())
{
try
{
//Read the contents of the SMS;
for(int i; i
in AndroidManifest.xml
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/9577/showart_1850111.html |
|