当任何来电按下拒绝按钮时,我想执行一些操作。我已经阅读了官方文档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;
}
}
}
}
当接收者拒绝来电时,它会向我展示敬酒,但我想从来电者一方这样做。
所以我只想找到当有人按下拒绝按钮来接听任何来电时的事件。
我该怎么做呢?