0

I'm trying to make the CallRedirectionService work. I have the following:

This is the manifast

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.HelpElderly"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
            android:name=".RedirectionService"
            android:permission="android.permission.BIND_CALL_REDIRECTION_SERVICE"
            android:exported="true">
            <intent-filter>
                <action android:name="android.telecom.CallRedirectionService"/>
            </intent-filter>
        </service>
    </application>

</manifest>

The redirection service:

class RedirectionService : CallRedirectionService() {
    override fun onPlaceCall(
        handle: Uri,
        initialPhoneAccount: PhoneAccountHandle,
        allowInteractiveResponse: Boolean
    ) {
        Log.d("AppLog", "handle:$handle , initialPhoneAccount:$initialPhoneAccount , allowInteractiveResponse:$allowInteractiveResponse")
        // Determine if the call should proceed, be redirected, or cancelled.
        val callShouldProceed = false
        val callShouldRedirect = false
        when {
            callShouldProceed -> {
                placeCallUnmodified()
            }
            callShouldRedirect -> {
                // Update the URI to point to a different phone number or modify the
                // PhoneAccountHandle and redirect.
                redirectCall(handle, initialPhoneAccount, true)
            }
            else -> {
                cancelCall()
            }
        }
    }
}

The main app:

class MainActivity : AppCompatActivity() {
    private val activity = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { ar: ActivityResult ->
        if(ar.resultCode == RESULT_OK){

        }
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Tell the system that you want your app to handle call redirects. This
        // is done by using the RoleManager to register your app to handle redirects.
        val roleManager = getSystemService(Context.ROLE_SERVICE) as RoleManager
        // Check if the app needs to register call redirection role.
        val shouldRequestRole = roleManager.isRoleAvailable(RoleManager.ROLE_CALL_REDIRECTION) &&
                !roleManager.isRoleHeld(RoleManager.ROLE_CALL_REDIRECTION)
        if (shouldRequestRole) {

            val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_CALL_REDIRECTION)
            activity.launch(intent)
        }
    }
}

My gradle config

namespace = "com.example.helpelderly"
compileSdk = 33

defaultConfig {
applicationId = "com.example.helpelderly"
minSdk = 29
targetSdk = 33
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

This is also the same as what the documentation suggested.

I tried to change the sdk, play with permissions, change the emulated phone. I have no idea why this is fails.

Ace
  • 1

0 Answers0