2

I am trying to add CallScreeningService in my android application(targetSdkVersion 29) without making my app a caller app. I follow all the instructions but still not getting it properly OR missing something there. Here is my code:

public class CallAppService extends CallScreeningService {
    @Override
    public void onScreenCall(Call.Details callDetails) {
        Log.e("CallBouncer", "Call screening service triggered");
        respondToCall(callDetails, new CallScreeningService.CallResponse.Builder().setDisallowCall(true).setRejectCall(true).build());
    }
}

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

Added following permission:

 <uses-permission android:name="android.Manifest.permission.READ_CONTACTS"/>
    <uses-permission android:name="android.Manifest.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.Manifest.permission.READ_CALL_LOG"/>
    <uses-permission android:name="android.Manifest.permission.PROCESS_OUTGOING_CALLS"/>
    <uses-permission android:name="android.Manifest.permission.ANSWER_PHONE_CALLS"/>

But still that this service is not invoking when I do a call. Is there anything that I am missing? I also see this issue but not getting the idea that why we need a ServiceConnection as it is not mentioned in the documentation.

user565
  • 871
  • 1
  • 22
  • 47

1 Answers1

0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
        Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING);
        startActivityForResult(intent, 1);
    }
Stav Bodik
  • 2,018
  • 3
  • 18
  • 25