I saw that in the reference docs, but I still can't figure out how to
make use of it.
Just referencing Context doesn't work:
Context.sendBroadcast(intent);

compile:
    [javac] Compiling 2 source files to /Users/SourceCode/android/
projects/AutoConference/bin/classes
    [javac] /Users/SourceCode/android/projects/AutoConference/src/org/
pythonistas/AutoConference/PhoneListener.java:27: non-static method
sendBroadcast(android.content.Intent) cannot be referenced from a
static context
    [javac]             Context.sendBroadcast(intent);
    [javac]                        ^
    [javac] /Users/SourceCode/android/projects/AutoConference/src/org/
pythonistas/AutoConference/PhoneListener.java:31: cannot find symbol
    [javac] symbol  : method sendBroadcast(android.content.Intent)
    [javac] location: class
org.pythonistas.AutoConference.PhoneListener
    [javac]             sendBroadcast(intent);
    [javac]                 ^
    [javac] 2 errors

I can't seem to find a way instantiate a copy of my activities
context.
I also don't really see a way to pass the context to the
PhoneListener, since it is created by startService:
package org.pythonistas.AutoConference;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;


public class PhoneBroadcaster extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent)
    {
        Intent phoneIntent = new Intent(context,
                                        PhoneListener.class);
        phoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startService(phoneIntent);
        TelephonyManager tManager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);
        PhoneListener pListener = new PhoneListener();
        tManager.listen(pListener,
                        PhoneStateListener.LISTEN_CALL_STATE);
    }

}




On Sep 17, 3:36 pm, Jack Ha <jack...@t-mobile.com> wrote:
> sendBroadcast() is part of the Context class.
>
> --
> Jack Ha
> Open Source Development Center
> ・T・ ・ ・Mobile・ stick together
> The coverage you need at the price you want
>
> The views, opinions and statements in this email are those of
> the author solely in their individual capacity, and do not
> necessarily represent those of T-Mobile USA, Inc.
>
> On Sep 16, 12:11 am, Tim <timothy.edwa...@gmail.com> wrote:
>
> > Im really new to android development (and java in general), and I seem
> > to have run into a design issue.
>
> > Background:
> >   Im working on an application that automatically turns the speaker
> > phone on when you are on a call and lay the phone down on a flat
> > surface.
> >   Since this is my first real android app, I am building it as I
> > learn.  Right now it isn't even running as a service.
> >   I have broken the app down so far, into an activity, a phone state
> > listener, and a sensor listener.  From the phone state listener, I am
> > trying to send the sensor listener a notification that the phone is
> > active (thus if the sensor listener detects it is lying flat then it
> > should turn on the speaker phone).
>
> > But I get an error when I try to compile my code
>
> > Code Snippet:
> > package org.pythonistas.AutoConference;
>
> > import android.telephony.PhoneStateListener;
> > import android.telephony.TelephonyManager;
> > import android.content.Intent;
> > import android.content.Context;
>
> > public class PhoneListener extends PhoneStateListener {
> >     protected static final String CALL_STATE_CHANGE =
> > "org.pythonistas.AutoConference.intent.action.CALL_STATE_CHANGE";
> >     protected static final String CALL_STATE_EXTRA = "callState";
> >     private Intent intent = new Intent(CALL_STATE_CHANGE);
> >     private Leveler myLevel = null;
> >     private CallReceiver myReceiver = null;
> >     public PhoneListener(){
> >         myLevel = new Leveler();
> >         myReceiver = new CallReceiver(myLevel);
> >     }
>
> >     public void onCallStateChanged(int state, String incomingNumber)
> >     {
> >         super.onCallStateChanged(state, incomingNumber);
>
> >         switch(state)
> >             {
> >             case TelephonyManager.CALL_STATE_IDLE:
> >                 intent.putExtra(CALL_STATE_EXTRA,false);
> >                 sendBroadcast(intent);
> >                 break;
> >             case TelephonyManager.CALL_STATE_OFFHOOK:
> >                 intent.putExtra(CALL_STATE_EXTRA,true);
> >                 sendBroadcast(intent);
> >                 break;
> >             }
> >     }
>
> > }
>
> > Compile Error:
> >     [javac] Compiling 3 source files to /Users/SourceCode/android/
> > projects/AutoConference/bin/classes
> >     [javac] /Users/SourceCode/android/projects/AutoConference/src/org/
> > pythonistas/AutoConference/PhoneListener.java:27: cannot find symbol
> >     [javac] symbol  : method sendBroadcast(android.content.Intent)
> >     [javac] location: class
> > org.pythonistas.AutoConference.PhoneListener
> >     [javac]             sendBroadcast(intent);
> >     [javac]                 ^
> >     [javac] /Users/SourceCode/android/projects/AutoConference/src/org/
> > pythonistas/AutoConference/PhoneListener.java:31: cannot find symbol
> >     [javac] symbol  : method sendBroadcast(android.content.Intent)
> >     [javac] location: class
> > org.pythonistas.AutoConference.PhoneListener
> >     [javac]             sendBroadcast(intent);
> >     [javac]                 ^
> >     [javac] 2 errors
>
> > Any help and/or guidance would be greatly appreciated.  I have also
> > posted my code on git  (http://github.com/tedwards/AutoConference )
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to