@@ -44,7 +44,10 @@ class MainActivity : AppCompatActivity() {
4444
4545 setupIntentLauncher()
4646 checkPermissionsAndRequest()
47- requestCallScreeningRole()
47+
48+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
49+ requestCallScreeningRole()
50+ }
4851 }
4952
5053 /* *
@@ -122,12 +125,7 @@ class MainActivity : AppCompatActivity() {
122125 showToast(this , getString(R .string.telecom_manager_unavailable))
123126 return
124127 }
125-
126- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ) {
127- requestRoleForQAndAbove()
128- } else {
129- requestRoleForBelowQ(telecomManager)
130- }
128+ requestRoleForQAndAbove()
131129 }
132130
133131 /* *
@@ -144,18 +142,4 @@ class MainActivity : AppCompatActivity() {
144142 showToast(this , getString(R .string.call_screening_role_prompt), Toast .LENGTH_LONG )
145143 }
146144 }
147-
148- /* *
149- * Requests the call screening role for Android P (API level 28) and below.
150- * @param telecomManager The TelecomManager for managing telecom services.
151- */
152- private fun requestRoleForBelowQ (telecomManager : TelecomManager ) {
153- if (telecomManager.defaultDialerPackage == packageName) {
154- showToast(this , getString(R .string.call_screening_role_already_granted))
155- } else {
156- val intent = Intent (Settings .ACTION_MANAGE_DEFAULT_APPS_SETTINGS )
157- startActivity(intent)
158- showToast(this , getString(R .string.call_screening_role_prompt), Toast .LENGTH_LONG )
159- }
160- }
161145}
0 commit comments