I'm making a call blocker for Android api 29. In order to do this, I have a class that extends CallScreeningService as explained here. My app can detect incoming and outgoing calls, but I don't know how to extract the phone number from Call.Details:
@RequiresApi(api = Build.VERSION_CODES.N)
public class CallScreenService extends CallScreeningService {
@RequiresApi(api = Build.VERSION_CODES.Q)
@Override
public void onScreenCall(Call.Details callDetails) {
CallResponse.Builder response = new CallResponse.Builder();
Log.i("CallScreeningService", callDetails.toString());
}
}
The log outputs "tel:**********" which I suspect means I don't have sufficient permissions to read the phone number. In Main I'm requesting permissions for all of the following:
android.Manifest.permission.READ_CONTACTS,
android.Manifest.permission.READ_PHONE_STATE,
android.Manifest.permission.READ_CALL_LOG,
android.Manifest.permission.PROCESS_OUTGOING_CALLS,
android.Manifest.permission.ANSWER_PHONE_CALLS,
Manifest.permission.CALL_PHONE
Additionally here is my Manifest for my CallScreening class:
<service android:name=".phoneHandlers.CallScreenService"
android:permission="android.permission.BIND_SCREENING_SERVICE">
<intent-filter>
<action android:name="android.telecom.CallScreeningService"/>
</intent-filter>
</service>
How can I read the phone number in Call.Details?
First, open the call icon app on the phone. Second, tap Recents to check the call history. The red icon refers to the incoming missed calls. The blue icon means the incoming calls that you had answered.
Enter an Android feature called Google Call Screen. Instead of taking the call yourself, you can have Google Assistant answer it for you, talk to the person on the other end and provide you with a real-time transcript. You then can decide if you want to take over or end the call.
To get the current phone number already connected to the call you need to use Call.Details#getHandle().
So inside your onScreenCall
:
@Override
public void onScreenCall(Call.Details callDetails) {
Log.i("Phone number", callDetails.getHandle().toString());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With