我有一个班级,一个电话状态的听众。在此,当此线路的通话断开时,
case TelephonyManager.CALL_STATE_IDLE:
Log.e(TAG, "CALL_STATE_IDLE");
break;
执行不止一次。这严重影响了我的要求。如果有人知道这个问题,请帮助我。
提前致谢
public class IncomingCallListener extends BroadcastReceiver
{
private Context mContext;
private static final String TAG = "CustomBroadcastReceiver";
@Override
public void onReceive(Context context, Intent intent)
{
mContext = context;
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
CustomPhoneStateListener customPhoneListener = new CustomPhoneStateListener();
telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Bundle bundle = intent.getExtras();
String phoneNr= bundle.getString("incoming_number");
}
public class CustomPhoneStateListener extends PhoneStateListener
{
private static final String TAG = "CustomPhoneStateListener";
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
switch (state)
{
case TelephonyManager.CALL_STATE_RINGING:
if(!incomingNumber.equalsIgnoreCase(""))
{
Log.e(TAG, "CALL_STATE_RINGING");
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.e(TAG, "CALL_STATE_OFFHOOK");
break;
case TelephonyManager.CALL_STATE_IDLE:
Log.e(TAG, "CALL_STATE_IDLE");
break;
default:
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
}