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

@ -56,7 +56,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.25.19'
implementation 'com.simplemobiletools:commons:5.25.21'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.klinkerapps:android-smsmms:5.2.6'

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