Help with a BraodcastReceiver

This is a discussion on Help with a BraodcastReceiver within the Android App Developers forums, part of the Droid Apps category; My situation is that I want to call a particular method to get called from ClassA from inside my ClassB which extends the BroadcastReceiver class. ...

+ Reply to Thread
Results 1 to 1 of 1

Thread: Help with a BraodcastReceiver

  1. Junior Droid
    r2sjoblom's Avatar
    Member #
    173795
    Join Date
    Feb 2011
    Posts
    10
    Phone
    droid x
    #1

    Help with a BraodcastReceiver

    My situation is that I want to call a particular method to get called from ClassA from inside my ClassB which extends the BroadcastReceiver class. I understand how to do this from inside another class file etc and how to setup the BroadcastReceiver, or so I thought.
    Below is the class file that extends the BroadcastReceiver.
    Code:
     public class WatchPhone extends BroadcastReceiver {
    private ClassA classA = new ClassA(); 
     
    @Override 
    public void onReceive(Context context, Intent BackToMain) { 
        // TODO Auto-generated method stub 
        TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);  
        int state = telephony.getCallState();  
        switch(state) {  
            case TelephonyManager.CALL_STATE_RINGING: 
                Log.d("TestServiceReceiver", "IDLE");  
                classA.IwantToDoThis(); 
                break;  
        } 
    }
    The method that I am trying to call does work great in the application if I manually request it. In my AndroidManifest.xml I added this

    Code:
        <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    and this at the bottom just above the closing application tag.
    Code:
                <receiver android:name=".WatchPhone"> 
                        <intent-filter>  
                        <action android:name="android.intent.action.PHONE_STATE" />  
                        </intent-filter>  
                </receiver>
    When the phone rings, the application crashes then closes. Any ideas on what I should do.
  2. Sponsor
    DF Advertising
    Join Date
    Nov 2008
    Location
    DroidForums.net
     
     
     
     

Sponsors

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts