MultiSmsSender/src/com/hectorone/multismssender/MessageReceiver.java

43 lines
1.3 KiB
Java
Raw Permalink Normal View History

2010-12-12 02:36:52 +01:00
package com.hectorone.multismssender;
2010-01-22 15:21:33 +01:00
import android.content.BroadcastReceiver;
import android.content.ContentValues;
2010-01-22 15:21:33 +01:00
import android.content.Context;
import android.content.Intent;
2010-01-27 17:59:55 +01:00
import android.net.Uri;
import android.telephony.SmsMessage;
2010-01-22 15:21:33 +01:00
public class MessageReceiver extends BroadcastReceiver{
2012-11-06 10:35:01 +01:00
public static final String MESSAGE_RECEIVED = "com.hectorone.multismssender.SMS_RECEIVED";
2010-01-27 13:47:08 +01:00
public static final String ANDROID_MESSAGE_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
2012-11-06 10:35:01 +01:00
public static final String DEBUG_TAG = "-------MessageReceiver--------";
2010-01-22 15:21:33 +01:00
@Override
public void onReceive(Context context, Intent intent) {
2010-01-27 13:47:08 +01:00
2010-01-27 17:59:55 +01:00
if (MESSAGE_RECEIVED.equals(intent.getAction())) {
2012-11-06 10:35:01 +01:00
//Log.d(DEBUG_TAG, "SMS_RECEIVED");
2010-01-27 17:59:55 +01:00
Uri entryURI = intent.getData();
if (entryURI != null){
byte[] pdu = intent.getByteArrayExtra("pdu");
//createFromPdu (byte[] pdu) will be deprecated.
//Use following instead
//String format = intent.getStringExtra("format");
//SmsMessage message = SmsMessage.createFromPdu(pdu, format);
SmsMessage message = SmsMessage.createFromPdu(pdu);
if(message.getStatus()== 0) {
ContentValues values = new ContentValues(1);
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_DELIVERED, 1);
context.getContentResolver().update(entryURI, values, null, null);
}
}
2010-01-22 15:21:33 +01:00
}
}
2010-01-27 13:47:08 +01:00
2010-01-22 15:21:33 +01:00
}