Can the SoundNotificaton be called from either the Receiver or the
PhoneStateListener?
On Mar 2, 6:36 pm, Bnet <tcb...@gmail.com> wrote:
> Okay Thanks. In regards to having a Context to call startActivity(),
> does it make sense to move the SoundNotification to the
> ServiceReceiver as shown below? I can't seem to basically call a
> subroutine.
>
> 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);
>
>         Intent i = new Intent
> ("com.bnet.detectmissedcall.SoundNotification");
>         context.startActivity(i);
>
>     }
>
> }
>
> -----------------
>
> public class SoundNotification extends Activity
> {
>
>         private static final int NOTIFY_ME_ID=1337;
>         private Timer timer=new Timer();
>
>         @Override
>         public void onCreate(Bundle savedInstanceState)
>         {
>                 super.onCreate(savedInstanceState);
>
>                                 TimerTask task=new TimerTask()
>                                 {
>                                         public void run()
>                                         {
>                                                 notifyMe();
>                                         }
>                                 };
>                                 timer.schedule(task, 5000);
>           }
>
>         private void notifyMe()
>         {
>                 final NotificationManager
> mgr=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
>
>                 Notification note=new Notification(R.drawable.icon,
> "Status message!", System.currentTimeMillis());
>
>                 note.vibrate = new long[] { 100,200,150, 500 };
>
>                                 note.defaults = Notification.DEFAULT_ALL;
>
>                                 PendingIntent 
> i=PendingIntent.getActivity(this,
> 0,
>                                                 new Intent(this,
> SoundNotification.class), 0);
>
>                                note.setLatestEventInfo(this, "Notification
> Title", "This is the notification message", i);
>
>                                 mgr.notify(NOTIFY_ME_ID, note);
>
>         }
>
> }
>
> On Mar 2, 2:17 pm, Marco Nelissen <marc...@android.com> wrote:
>
>
>
> > 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.- 
> > >> Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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