android - How to call an activity to foreground when we receiving a call? -


i stuck in process. trying implement setting video caller id when call on mobile.

here sample code:

public class mainactivity extends activity {  videoview videoview; telephonymanager telephonymanager; string videopath= environment.getexternalstoragedirectory() + "/"         + "video.mp4"; //mediacontroller mediacontroller;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      videoview = (videoview) findviewbyid(r.id.videoview1);     //mediacontroller = new mediacontroller(this);     telephonymanager = (telephonymanager) getsystemservice(context.telephony_service);     phonestatelistener psl = new phonestatelistener() {         @override         public void oncallstatechanged(int state, string incomingnumber) {             // todo auto-generated method stub              if (state == telephonymanager.call_state_ringing) {                 intent intent2open = new intent(mainactivity.this,                         mainactivity.class);                 intent2open.setflags(intent.flag_activity_brought_to_front                         | intent.flag_activity_new_task                         | intent.flag_activity_previous_is_top                         | intent.flag_activity_multiple_task);                 intent2open.setaction("android.intent.action.view");                 intent2open.addflags(intent.flag_activity_clear_top);                 intent2open.setaction(intent.action_main);                 intent2open.addcategory(intent.category_launcher);                 intent2open.setflags(0);                 sendbroadcast(intent2open);                 videoview.setvideopath(videopath);                  videoview.start();                 videoview.bringtofront();                 toast.maketext(getapplicationcontext(),                         "incoming call" + incomingnumber, toast.length_long)                         .show();             }             super.oncallstatechanged(state, incomingnumber);         }     };     telephonymanager.listen(psl, phonestatelistener.listen_call_state);  } 

and here broadcast receiver code:

public class callreceiver extends broadcastreceiver {  @override public void onreceive(context context, intent intent) {     // todo auto-generated method stub       string state = intent.getstringextra(telephonymanager.extra_state);     toast.maketext(context, state, 0).show();     if(state.equals(telephonymanager.call_state_ringing))     {         intent intent2 = new intent(context,mainactivity.class);         intent2.putextras(intent2);         intent2.addflags(intent.flag_activity_new_task);         context.startactivity(intent2);      } } } 

can please me find what's wrong code?


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -