got my answers.. sorry for being so stupid.. -- Vikrant
On Wed, Sep 22, 2010 at 5:25 PM, Vijay Vikrant <[email protected]>wrote: > Thanks for responding.. > > Below is a shabby but simple piece of code that i am experimenting with.. > The onReceive function does have a context - But i just register a > phonestate listener in there and then i have to raise a toast while i am in > the phonestatelistener function. What can i change? > > > package com.android.prankapp; > > import android.content.BroadcastReceiver; > import android.content.Context; > import android.content.Intent; > import android.os.Bundle; > import android.telephony.PhoneStateListener; > import android.telephony.TelephonyManager; > import android.util.Log; > import android.content.BroadcastReceiver; > import android.widget.Toast; > > public class PrankAApp extends BroadcastReceiver { > > @Override > public void onReceive(Context context, Intent intent) { > Log.d("PrankAApp","BEGIN1"); > if(intent.getData()!=null) > { > Log.d("PrankAApp",intent.getDataString() ); > } > else > { > Log.d("PrankAApp","DataString == NULL" ); > } > Log.d("PrankAApp",intent.toString()); > TelephonyManager myTelManager = > (TelephonyManager)context.getSystemService(context.TELEPHONY_SERVICE); > MyPhoneStateListener myListner = new MyPhoneStateListener(); > myTelManager.listen(myListner, > PhoneStateListener.LISTEN_CALL_STATE); > } > > private class MyPhoneStateListener extends PhoneStateListener > { > private static final int CALL_STATE_RINGING = 1; > private static final int CALL_STATE_IDLE = 0; > > public void onCallStateChanged (int state, String incomingNumber) > { > if (state == CALL_STATE_RINGING) { > resolveNumber(incomingNumber); > } > } > } > > private void resolveNumber ( String incomingNumber) > { > int duration = Toast.LENGTH_SHORT; > CharSequence text = incomingNumber; > Toast toast = Toast.makeText(this, text, duration); *<=== How do i > get context here????* > toast.show(); > } > } > > -- Vikrant > > > > > On Wed, Sep 22, 2010 at 5:08 PM, Mark Murphy <[email protected]>wrote: > >> On Wed, Sep 22, 2010 at 7:35 AM, Vijay Vikrant <[email protected]> >> wrote: >> > Can somebody throw some light on how to display a >> > pop-up/notification/toast while i am in a broadcast receiver. Toast >> expects >> > a context and i don't have a context to pass. >> >> Sure you do. Look at the first parameter to onReceive(). >> >> -- >> Mark Murphy (a Commons Guy) >> http://commonsware.com | http://github.com/commonsguy >> http://commonsware.com/blog | http://twitter.com/commonsguy >> >> _The Busy Coder's Guide to Android Development_ Version 3.1 Available! >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to [email protected] >> To unsubscribe from this group, send email to >> [email protected]<android-developers%[email protected]> >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en > > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

