How to implement CallScreeningService for Andoid<=28

433 views Asked by At

**What I have done so far : **

I have implement it for Android SDK 29

 RoleManager roleManager = (RoleManager) getSystemService(ROLE_SERVICE);
 Intent intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_SCREENING);
 startActivityForResult(intent, REQUEST_ID1);

**What I am looking for ? : **

I want to implement Call Screening Service for devices < SDK 29. Kindly help me if anyone have done it before.

2

There are 2 answers

1
Iván Garza Bermea On

Unfortunately, you can't.

It is impossible to access the RoleManager class on Android versions < 29 because this class was introduced on Android 29. Therefore, you can only use this class on devices running Android 29 and up.

0
Tolis On

For Android <= 28, to bind the CallScreeningService the app must be set as the default dialer app. On runtime, a dialog can be displayed asking the user to set your app as the default dialer app as follows:

if (getSystemService(TelecomManager.class).getDefaultDialerPackage() != getPackageName()) {
                    Intent changedDialer= new Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER);
                    changedDialer.putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, getPackageName());
                    startActivity(ChangeDialer);
      }