check if the SMS Role exists before relying on it

This commit is contained in:
tibbi 2020-04-15 21:15:10 +02:00
parent a91c8d7334
commit fb5f67d5b6
2 changed files with 10 additions and 5 deletions

View file

@ -48,11 +48,16 @@ class MainActivity : SimpleActivity() {
if (isQPlus()) {
val roleManager = getSystemService(RoleManager::class.java)
if (roleManager!!.isRoleHeld(RoleManager.ROLE_SMS)) {
askPermissions()
if (roleManager!!.isRoleAvailable(RoleManager.ROLE_SMS)) {
if (roleManager.isRoleHeld(RoleManager.ROLE_SMS)) {
askPermissions()
} else {
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
}
} else {
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
toast(R.string.unknown_error_occurred)
finish()
}
} else {
if (Telephony.Sms.getDefaultSmsPackage(this) == packageName) {