Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:26:58+00:00 2026-05-24T20:26:58+00:00

So this is my BroadcastReceiver public class IncomingSMSListener extends BroadcastReceiver { private static final

  • 0

So this is my BroadcastReceiver

public class IncomingSMSListener extends BroadcastReceiver {
private static final String SMS_EXTRA_NAME = "pdus";

@Override
public void onReceive(Context context, Intent intent) {
    SmsMessage[] messages = fetchSMSMessagesFromIntent(intent);
}

private SmsMessage[] fetchSMSMessagesFromIntent(Intent intent) {
    ArrayList<SmsMessage> receivedMessages = new ArrayList<SmsMessage>();
    Object[] messages = (Object[]) intent.getExtras().get(SMS_EXTRA_NAME);
    for (Object message : messages) {
        SmsMessage finalMessage = SmsMessage
                .createFromPdu((byte[]) message);
        receivedMessages.add(finalMessage);
    }
    return receivedMessages.toArray(new SmsMessage[0]);
}

}

I’m being able to read the incoming message just fine and all, but let’s say from here I want to forward the message to another phone number and make sure it got sent. I know I can do SmsManager.sendTextMessage() but how do I set up the PendingIntent part to be notified whether the SMS got sent or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:27:01+00:00Added an answer on May 24, 2026 at 8:27 pm

    OK, ended up finding the solution in the end. Since the context passed in to the onReceive() method in the BroadCastReceiver doesn’t let me register other BroadcastReceivers to listen for the “message sent” event, I ended up getting a grip of the app context and doing what follows:

    In the BroadcastReceiver:

    SmsManager smsManager = SmsManager.getDefault();
        Intent intent = new Intent(SENT_SMS_FLAG);
        PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0,
                intent, 0);
        SMSForwarderApp.getAppContext().registerReceiver(
                new MessageSentListener(),
                new IntentFilter(SENT_SMS_FLAG));
        smsManager.sendTextMessage("Here goes the destination of the SMS", null,
                "Here goes the content of the SMS", sentIntent, null);
    

    SENT_SMS_FLAG is simply a static string that uniquely identifies the intent I just made. My MessageSentListener looks like this:

    public class MessageSentListener extends BroadcastReceiver{
    
    @Override
    public void onReceive(Context context, Intent intent) {
        int resultCode = this.getResultCode();
        boolean successfullySent = resultCode == Activity.RESULT_OK;
        //That boolean up there indicates the status of the message
        SMSForwarderApp.getAppContext().unregisterReceiver(this);
                //Notice how I get the app context again here and unregister this broadcast
                //receiver to clear it from the system since it won't be used again
    }
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is how my BroadcastReceiver looks like: public class IncomingSMSListener extends BroadcastReceiver { private
I have this Broadcast receiver registered public class NotifyAlarmBroadcast extends BroadcastReceiver{ public Context context;
This is my code: Activity: @Override public void onCreate(Bundle savedInstanceState) { ... Intent intent
This code isn't work. What happen? public class Main extends Activity { /** Called
call.java: public class Call extends Activity{ boolean timerhasstarted; Intent callIntent; public void onCreate(Bundle savedInstanceState)
I created a broadcast receiver to start activity onReceive like this: public class BroadcastReceiver1
I got this code from somewhere, a book I think: public class KITSMSReceiver extends
I can call an Activity from a BroadcastReceiver by this way: public class AlarmReceiver
my code is public class AlarmReceiver extends BroadcastReceiver { public Notification mNotification = null;
This is my code: public class Alarm extends Activity { /** Called when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.