Android reject incoming call

2019-03-04 14:12发布

问题:

In my android project(with target sdk version 23), I want reject incoming call. I know that there are a lot of question about this, in particular

1 How to import com.android.internal.telephony.ITelephony to the Android application

2 How to Reject a call programatically in android

3 How to reject any incoming call when I have already detected it

In the first one link, the suggest solution is use reflection on the interface ITelephony because it's an internal interface. But this solution use MODIFY_PHONE_STATE permission, which can only be granted to system apps so it won't work anyway.

From second and third link, I understand that solution is copy ITelephony from here then put it in a new package of com.android.internal.telephony in my solution. The problem is that in this interface there are a lot of problem about find of class android.telephony.RadioAccessFamily (error cannot find symbol class RadioAccessFamily), that class is in platform framework base of android.

Any idea for resolve this problem?

回答1:

I found the answer myself. For others interested, here here it is:

create aidl folder in main folder.

create package com.android.internal.telephony in aidl folder

create a aidl file in package:

interface ITelephony {      

    boolean endCall(); 
    void answerRingingCall();      

}

for the code about end call see the answer in the link.

and it's not necessary add the permission

android.permission.MODIFY_PHONE_STATE