I'm trying to set up one class for receiving sms and sent status.
This is how my manifest looks for this task:
<receiver android:name=".SmsListener" android:permission="android.permission.BROADCAST_SMS" android:exported="true">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.provider.Telephony.SMS_SENT" />
Intent _intent = new Intent();
_intent.setClass(ParkingOptionsActivity.this, SmsListener.class); // SmsListener extends BroadcastReceiver
_pendingIntent = PendingIntent.getActivity(ParkingOptionsActivity.this, 0, _intent, 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, "test message", _pendingIntent, null);
You need to obtain your
getBroadcast() instead of
getActivity(), since you want to send a broadcast to your
BroadcastReceiver, not start an
In your current code, you can simply change that one line:
_pendingIntent = PendingIntent.getBroadcast(ParkingOptionsActivity.this, 0, _intent, 0);
"android.provider.Telephony.SMS_SENT" action is not present in the SDK currently, and there is no system broadcast when an SMS is sent. Your app doesn't really need that
<action> in the manifest entry, since the
Intent is explicitly targeting your Receiver class.
If you do plan to use that action for something else - e.g., differentiating broadcasts in
onReceive(), receiving implicit broadcasts from other apps, etc. - then you might consider changing it to use something other than the
android.provider.Telephony package name, so as not to cause potential unwanted behavior or confusion in the future. Using your own app's package name is the norm, I would say.