Skip to content Skip to sidebar Skip to footer

Telecommanager.action_change_default_dialer Returns Result_canceled On Huawei P8 Lite

I want to change Android default dialer and want to make my own customized dialer. For this purpose I have choose this GIthub repo as start up project. This works well on all othe

Solution 1:

If you run this code in Android Q or above it will not work. Its just fine for below Q. To get it working in Android Q try the code below:

RoleManager rm = (RoleManager) getSystemService(Context.ROLE_SERVICE);
startActivityForResult(rm.createRequestRoleIntent(RoleManager.ROLE_DIALER), 120);

It will popup the app chooser dialog.

Solution 2:

You'll also get a RESULT_CANCELED when targeting Android Q or higher, as the PermissionPolicyService removes the Action. You should use RoleManager.createRequestRoleIntent() instead.

Solution 3:

Try to add some intent filters to your Activity in AndroidManifest.

<intent-filter><actionandroid:name="android.intent.action.VIEW"/><actionandroid:name="android.intent.action.DIAL"/><categoryandroid:name="android.intent.category.DEFAULT"/><categoryandroid:name="android.intent.category.BROWSABLE"/><dataandroid:scheme="tel"/></intent-filter><intent-filter><actionandroid:name="android.intent.action.DIAL"/><categoryandroid:name="android.intent.category.DEFAULT"/></intent-filter>

Solution 4:

My way:

@SuppressLint("QueryPermissionsNeeded")@TargetApi(Build.VERSION_CODES.M)funlaunchSetDefaultDialerIntent(activity: AppCompatActivity) {
    Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(
        TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME,
        activity.packageName
    ).apply {
        if (resolveActivity(activity.packageManager) != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
                val rm: RoleManager? = activity.getSystemService(RoleManager::class.java)
                if (rm?.isRoleAvailable(RoleManager.ROLE_DIALER) == true) {
                    @Suppress("DEPRECATION")
                    activity.startActivityForResult(
                        rm.createRequestRoleIntent(RoleManager.ROLE_DIALER),
                        REQUEST_CODE_SET_DEFAULT_DIALER
                    )
                }
            } else {
                @Suppress("DEPRECATION")
                activity.startActivityForResult(this, REQUEST_CODE_SET_DEFAULT_DIALER)
            }
        } else {
            activity.toastShort(R.string.no_contacts_found)
        }
    }
}

Then use it directly in Activity.

Post a Comment for "Telecommanager.action_change_default_dialer Returns Result_canceled On Huawei P8 Lite"