broadcastreceiver - Holding music service during call Android Programmatically -


i building music player , able play music in background through music service. problem arises when receive call service still running in background. want hold music service during call.

reference

stopping & starting music on incoming calls

i try creating receiver got error

phonereciever.java

public class phonereceiver extends broadcastreceiver{  telephonymanager telmanager; context context;  @override public void onreceive(context context, intent intent) {     // todo auto-generated method stub     this.context=context;      telmanager = (telephonymanager)context.getsystemservice(context.telephony_service);     telmanager.listen(phonelistener, phonestatelistener.listen_call_state);  }  private final phonestatelistener phonelistener = new phonestatelistener(){      @override     public void oncallstatechanged(int state, string incomingnumber) {         // todo auto-generated method stub         try {             switch (state) {             case telephonymanager.call_state_ringing: {                 //pause                  break;             }             case telephonymanager.call_state_offhook: {                  break;             }             case telephonymanager.call_state_idle: {                 //play                  break;             }             default: { }             }         }          catch (exception ex) {          }     } }; } 

added in manifest.xml in

 <receiver android:name=".phonereceiver" >     <intent-filter>         <action android:name="android.intent.action.phone_state" >         </action>     </intent-filter> </receiver> 

logcat:

enter image description here please if noticed mistake or other way it.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -