これは私のサービスファイルです:
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);
}
}
};
「SMSCounterService: Constructor」というログが表示されます。そのため、onCreate() メソッドが呼び出されます。しかし、SMS を送信すると、BroadcastReceiver はそれを識別できません。