<activity
android:name=".phone.view.PhoneCallActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:exported="true">
<!-- region provides ongoing call UI -->
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tel" />
</intent-filter>
<!-- endregion -->
<!-- region provides dial UI -->
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<!-- endregion -->
</activity>
fun buildSetDefaultPhoneCallAppIntent(): Intent? {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
Intent().apply {
action = TelecomManager.ACTION_CHANGE_DEFAULT_DIALER
putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, MainApp.context.packageName)
} else null
}
fun setDefaultPhoneCallApp(activity: FragmentActivity): Boolean {
return buildSetDefaultPhoneCallAppIntent()?.let {
if(it.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){
activity.startActivityForResult(rm.createRequestRoleIntent(RoleManager.ROLE_DIALER),100)
}
}else {
activity.startActivityForResult(it,100)
}
}else {
it.flags = Intent.FLAG_ACTIVITY_NEW_TASK
MainApp.context.startActivity(it)
}
true
} ?: false
}
fun isDefaultPhoneCallApp(): Boolean {
val manger = MainApp.context.getSystemService(Context.TELECOM_SERVICE) as? TelecomManager
if (manger != null && manger.defaultDialerPackage != null) {
return manger.defaultDialerPackage == MainApp.context.packageName
}
return false
}