androidlinuxandroid-studioapkandroid-manifest

How to make an App to the default phone app


I am new to Android app development. So I'm wondering what I need to do to make my app the default phone app. If anyone can help me I would be very grateful

Best regards Raphael Schneider

A photo of the default phone app settings

I've already tried a few things in the Android Manifest, but that didn't work.

Chatgpt couldn't help me either


Solution

  • To list your app, as a dialer, so that the OS, can list it in the above settings page

    You can declare the permission MANAGE_OWN_CALLS in your Manifest file. You can read about it here

    And you can ask the user to set your app as the default dialer. As Gabe pointed out, you cannot do that programatically, but you can prompt the user to do so

    Reference code taken from here

    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)
            }
        }