How can I answer a phone call and hang it up?

后端 未结 3 544
迷失自我
迷失自我 2020-12-18 10:42

I have code which is supposed to answer the phone and hang up right away when someone calls the phone. I get no errors and no force close when the call comes in from a diffe

3条回答
  •  甜味超标
    2020-12-18 11:20

    I don't think you want to do telephonyService.endCall() in getTeleService(). You probably want to call that within the onReceive method instead.

    I'm not sure whether you want to reject all calls or only ones from certain numbers. If you are trying to only reject certain numbers, it looks like you don't have any code to check the number of the incoming call against the blocked numbers after retrieving it here:

    public void onReceive(Context context, Intent intent) {
        Bundle b = intent.getExtras();
        incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
    --->// Additional Step                                                       <---
    --->// Check whether this number matches with your defined Block List        <---
    --->// If yes, Reject the Call                                               <---
    }
    

    You can try changing it to the following if you want to check the number and reject calls only from the blocked numbers:

    public void onReceive(Context context, Intent intent) {
        Bundle b = intent.getExtras();
        incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
    
        // Additional Step
        // Check whether this number matches with your defined Block List
        // If yes, Reject the Call
        for (int i=0; i

    Or if you just want to reject all calls, it's even simpler:

    public void onReceive(Context context, Intent intent) {
        telephonyService.endCall();
    }
    

提交回复
热议问题