This is my service file:
public class SMSCounterService extends Service {
/** Called when the activity is first created. */
@Override
public void onCreate() {
Log.d(LOG_TAG, "SMSCounterService: Constructor");
super.onCreate();
dbActivities = new DBActivities(this);
dbActivities.open(); // Create or open the existing DB if already created
IntentFilter filter = new IntentFilter();
filter.addAction("android.provider.Telephony.SMS_SENT");
registerReceiver(receiver, filter);
}
@Override
public void onDestroy() {
unregisterReceiver(receiver);
dbActivities.close();
super.onDestroy();
}
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_SENT")) {
smsCount++;
Log.d(LOG_TAG, "SMSCounterService: smsCount=" +smsCount);
long dbInsertReturn = dbActivities.insertIntoDB(smsCount);
}
}
};
I can see the log “SMSCounterService: Constructor”. So the onCreate() method is called. But when I send an SMS, the BroadcastReceiver is not able to identify it.
AFAIK, there is no intent like android.provider.Telephony.SMS_SENT.
I did “grep” through Ice Cream Sandwich and couldn’t find it.
Go with ContentObserver approach. Register your observer to listen to updates messaging provider.
(Decided to register it as an answer, who knows maybe somebody will accept it 😉 )