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

<p>By the way the error it gives is "The method setReceiver(SmsObserver) is undefined for the type Context"</p>

<p>My code:</p>

<pre><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);

}
</code></pre>

<p>}</p>
