require being set as the default SMS app on QPlus too

This commit is contained in:
tibbi 2020-04-04 16:58:13 +02:00
parent 4273ff0b22
commit 3637afc0bb
1 changed files with 13 additions and 4 deletions

View File

@ -1,6 +1,8 @@
package com.simplemobiletools.smsmessenger.activities package com.simplemobiletools.smsmessenger.activities
import android.annotation.SuppressLint
import android.app.Activity import android.app.Activity
import android.app.role.RoleManager
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.provider.Telephony import android.provider.Telephony
@ -27,6 +29,7 @@ class MainActivity : SimpleActivity() {
private var storedTextColor = 0 private var storedTextColor = 0
private val MAKE_DEFAULT_APP_REQUEST = 1 private val MAKE_DEFAULT_APP_REQUEST = 1
@SuppressLint("InlinedApi")
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
@ -36,11 +39,17 @@ class MainActivity : SimpleActivity() {
return return
} }
if (Telephony.Sms.getDefaultSmsPackage(this) == packageName) { if (isQPlus()) {
val roleManager = getSystemService(RoleManager::class.java)
if (roleManager!!.isRoleHeld(RoleManager.ROLE_SMS)) {
askPermissions() askPermissions()
} else { } else {
if (isQPlus()) { val intent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
startActivityForResult(intent, MAKE_DEFAULT_APP_REQUEST)
}
} else {
if (Telephony.Sms.getDefaultSmsPackage(this) == packageName) {
askPermissions()
} else { } else {
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT) val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName) intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)