public class LoudSpeakerOnOff extends BroadcastReceiver{
TelephonyManager tm;
public static ITelephony telephonyService;
public static AudioManager am;
Context context;
boolean loudspeakerOn = false, vibrateOn = false;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
this.context = context;
am = (AudioManager)context.getSystemService("audio");
tm = (TelephonyManager)context.getSystemService("phone");
tm.listen(new phoneState(), PhoneStateListener.LISTEN_CALL_STATE);
}
class phoneState extends PhoneStateListener{
public void onCallStateChanged(int state, String incomingNumber){
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
am.setSpeakerphoneOn(false);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
am.setSpeakerphoneOn(true);
break;
case TelephonyManager.CALL_STATE_RINGING:
break;
}
}
}
}
TelephonyManager tm;
public static ITelephony telephonyService;
public static AudioManager am;
Context context;
boolean loudspeakerOn = false, vibrateOn = false;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
this.context = context;
am = (AudioManager)context.getSystemService("audio");
tm = (TelephonyManager)context.getSystemService("phone");
tm.listen(new phoneState(), PhoneStateListener.LISTEN_CALL_STATE);
}
class phoneState extends PhoneStateListener{
public void onCallStateChanged(int state, String incomingNumber){
switch(state){
case TelephonyManager.CALL_STATE_IDLE:
am.setSpeakerphoneOn(false);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
am.setSpeakerphoneOn(true);
break;
case TelephonyManager.CALL_STATE_RINGING:
break;
}
}
}
}