简体   繁体   中英

Get incoming call number programmatically on android 10

Looking at previous solutions for this problem are now depreciated as of api 29(Android 10). Has anyone been able to get the incoming phone number on for api 29. Apparently now to do this you need to use CallScreeningService

Yes, implement the class and add the necessary permission below in the manifest:

  <service
        android:name=".CallScreeningService"
        android:permission="android.permission.BIND_SCREENING_SERVICE">
        <intent-filter>
            <action android:name="android.telecom.CallScreeningService" />
        </intent-filter>
    </service>

Within onScreenCall(Call.Details details) you can call details.getHandle() which returns the telephone number of the incoming call. This will only get called if the number cannot be matched to the contact information existing on the device.

@Override
public void onScreenCall(Call.Details details) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        if(details.getCallDirection() == Call.Details.DIRECTION_INCOMING) {
            CallResponse.Builder response = new CallResponse.Builder();
            response.setDisallowCall(false);
            response.setRejectCall(false);
            response.setSilenceCall(false);
            response.setSkipCallLog(false);
            response.setSkipNotification(false);
            details.getHandle(); //This is the calling number
            respondToCall(details, response.build());

        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM