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 7194373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:21:30+00:00 2026-05-28T20:21:30+00:00

I am using a Broadcast Receiver to receive a Broadcast when the phone boots

  • 0

I am using a Broadcast Receiver to receive a Broadcast when the phone boots up, and from there I’d like to register a PhoneStateListener and ContentObserver. Unfortunately it won’t let me use the setReceiver() method for the ContentObserver like in my main activity. There was a similar problem with PhoneStateListener and startService(), but I was able to use the passed context to make it work. This does not solve the problem for setReceiver. What is the correct way of calling this method?

By the way the error it gives is “The method setReceiver(SmsObserver) is undefined for the type Context”

My code:

public class BootReceiver extends BroadcastReceiver {

private Context mContext;

@Override
public void onReceive(Context context, Intent intent) {

    mContext = context;

    // Get the telephony manager
            TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);

            // Create a new PhoneStateListener
            PhoneStateListener listener = new PhoneStateListener() {

                @Override
                public void onCallStateChanged(int state, String incomingNumber) {
                    if (state == TelephonyManager.CALL_STATE_IDLE) {
                        Intent update = new Intent(mContext,
                                UpdateService.class);
                        mContext.startService(update);
                    }
                }

                @Override
                public void onDataActivity(int direction) {
                    if (direction == TelephonyManager.DATA_ACTIVITY_NONE) {
                        Intent update = new Intent(mContext,
                                UpdateService.class);
                        mContext.startService(update);
                    }
                }
            };

            // Register the listener with the telephony manager
            telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
            telephonyManager.listen(listener,
                    PhoneStateListener.LISTEN_DATA_ACTIVITY);

            SmsObserver smsSentObserver = new SmsObserver(new Handler(), mContext);

            //Unable to call this method
            mContext.setReceiver(smsSentObserver);

}

}

  • 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-28T20:21:31+00:00Added an answer on May 28, 2026 at 8:21 pm

    This does not solve the problem for setReceiver. What is the correct way of calling this method?

    Tactically, there is no setReceiver() method anywhere in Android. If SmsObserver is supposed to be a ContentObserver, you would use a ContentResolver and notifyChange() to register it.

    Strategically, your code is useless, as your process can be terminated shortly after onReceive() ends, making all this work moot.

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

Sidebar

Related Questions

I am using an broadcast receiver for Intent.ACTION_BATTERY_CHANGED. Rate at which I receive this
I'm trying to receive SMS using broadcast receiver. MySMSReceiver : import android.content.BroadcastReceiver; import android.content.Context;
Using broadcast receiver, it's easy to find out whether now the phone is plugged
I am using sms broadcast receiver in my application. When i send first sms
Hai i developed a application using broadcast receiver.I need to wake my Application always.so
I am trying to get all installed applications using intents and broadcast receiver ,
I am using ACTION_DATE_CHANGED in my Broadcast Receiver, and android.intent.action.DATE_CHANGED in <receiver>...</receiver> in my
Hai am trying to get the gps location using BroadCast Receiver.its working fine,But i
Can an activity be invoked using a BroadcastReceiver ? The onReceive for BroadCast receiver
In my application I am listening for following 3 intents by using broadcast receiver.

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.