我想在按任何来电的拒绝按钮时执行一些操作。我已经阅读了官方文档TelephonyManager,但它不能满足我的需要。
我试过这个没有成功。
public class Call_Receiver extends BroadcastReceiver {
private Context ctx;
@Override
public void onReceive(Context context, Intent intent) {
ctx = context;
OutgoingIncomingCallListener phoneListener = new OutgoingIncomingCallListener();
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if (intent.getAction()
.equals("android.intent.action.NEW_OUTGOING_CALL")) {
telephony.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
}
}
class OutgoingIncomingCallListener extends PhoneStateListener {
public boolean wasRinging;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
wasRinging = true;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i("", " *********** OFFHOOK ********");
wasRinging = true;
break;
case TelephonyManager.CALL_STATE_IDLE:
if (wasRinging) {
Toast.makeText(ctx,
"Your call is disconnected by receiver", 10000)
.show();
}
wasRinging = true;
break;
}
}
}
}
当接收者拒绝接听电话时,它会向我显示吐司,但我想从来电方那边做 因此,当有人按下拒绝按钮进行任何来电时,我想找到该事件。
我该怎么做?