Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract phone number from Call.Details in CallScreeningService?

Tags:

android

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?

like image 935
Jaitnium Avatar asked Jun 28 '19 22:06

Jaitnium


People also ask

How can I get incoming call details of a number?

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.

What is Call screening service?

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.


Video Answer


1 Answers

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());
}
like image 106
Ibrahim Ali Avatar answered Oct 02 '22 12:10

Ibrahim Ali