That won't work, because your PhoneStateListener is going to disappear
as soon as (or shortly after) you return from onReceive().
You should have your receiver start a Service that hosts the PhoneStateListener.



On Mon, Mar 2, 2009 at 12:03 PM, Bnet <tcb...@gmail.com> wrote:
>
> Following is the receiver
>
>
> import android.content.BroadcastReceiver;
> import android.content.Context;
> import android.content.Intent;
> import android.telephony.PhoneStateListener;
> import android.telephony.TelephonyManager;
>
>
> public class ServiceReceiver extends BroadcastReceiver {
>
>       �...@override
>        public void onReceive(Context context, Intent intent) {
>                MyPhoneStateListener phoneListener=new MyPhoneStateListener();
>        TelephonyManager telephony = (TelephonyManager)
> context.getSystemService(Context.TELEPHONY_SERVICE);
>        telephony.listen
> (phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
>
>
>
>
>    }
> }
>
> On Mar 2, 1:55 pm, Marco Nelissen <marc...@android.com> wrote:
>> On Mon, Mar 2, 2009 at 11:49 AM, Bnet <tcb...@gmail.com> wrote:
>>
>> > Thanks for your time Marco, added the following to the manifest. There
>> > is an error in MyPhoneStateListener as shown below:
>>
>> >         <activity android:name=".SoundNotification">
>> >                <intent-filter>
>> >                <action
>> > android:name="android.intent.action.SoundNotification" />
>>
>> You should use the same string here that you use for the intent
>> action, i.e. "com.bnet.detectmissedcall.SoundNotification"
>>
>> >                </intent-filter>
>> >         </activity>
>>
>> > Error: The method startActivity(Intent) is undefined for the type
>> > MyPhoneStateListener
>>
>> > Intent i = new Intent("com.bnet.detectmissedcall.SoundNotification");
>> > startActivity(i);
>>
>> You will need to have a Context to call startActivity() on. It's not
>> clear to me how you create your PhoneStateListener, but the Activity
>> or Service that you create it in should have a Context for you to use.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to