Skip to content

Commit fb5f67d

Browse files
committed
check if the SMS Role exists before relying on it
1 parent a91c8d7 commit fb5f67d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ android {
5656
}
5757

5858
dependencies {
59-
implementation 'com.simplemobiletools:commons:5.25.19'
59+
implementation 'com.simplemobiletools:commons:5.25.21'
6060
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
6161
implementation 'org.greenrobot:eventbus:3.2.0'
6262
implementation 'com.klinkerapps:android-smsmms:5.2.6'

app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ class MainActivity : SimpleActivity() {
4848

4949
if (isQPlus()) {
5050
val roleManager = getSystemService(RoleManager::class.java)
51-
if (roleManager!!.isRoleHeld(RoleManager.ROLE_SMS)) {
52-
askPermissions()
51+
if (roleManager!!.isRoleAvailable(RoleManager.ROLE_SMS)) {
52+
if (roleManager.isRoleHeld(RoleManager.ROLE_SMS)) {
53+
askPermissions()
54+
} else {
55+
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
56+
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
57+
}
5358
} else {
54-
val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
55-
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
59+
toast(R.string.unknown_error_occurred)
60+
finish()
5661
}
5762
} else {
5863
if (Telephony.Sms.getDefaultSmsPackage(this) == packageName) {

0 commit comments

Comments
 (0)