adding a helper function for checking if the app is set as the default dialer
This commit is contained in:
parent
b6e00fba44
commit
7331217e8a
|
@ -11,6 +11,7 @@ import android.telecom.TelecomManager
|
|||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.extensions.isDefaultDialer
|
||||
import com.simplemobiletools.contacts.pro.extensions.telecomManager
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
|
@ -25,7 +26,7 @@ class DialerActivity : SimpleActivity() {
|
|||
callNumber = intent.data
|
||||
|
||||
// make sure Simple Contacts is the default Phone app before initiating an outgoing call
|
||||
if (telecomManager.defaultDialerPackage != packageName) {
|
||||
if (!isDefaultDialer()) {
|
||||
val intent = Intent(TelecomManager.ACTION_CHANGE_DEFAULT_DIALER).putExtra(TelecomManager.EXTRA_CHANGE_DEFAULT_DIALER_PACKAGE_NAME, packageName)
|
||||
startActivityForResult(intent, REQUEST_CODE_SET_DEFAULT_DIALER)
|
||||
} else {
|
||||
|
@ -56,7 +57,7 @@ class DialerActivity : SimpleActivity() {
|
|||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, resultData)
|
||||
if (requestCode == REQUEST_CODE_SET_DEFAULT_DIALER) {
|
||||
if (telecomManager.defaultDialerPackage != packageName) {
|
||||
if (!isDefaultDialer()) {
|
||||
finish()
|
||||
} else {
|
||||
initOutgoingCall()
|
||||
|
|
|
@ -338,3 +338,6 @@ fun Context.deleteBlockedNumber(number: String) {
|
|||
val uri = contentResolver.insert(BlockedNumbers.CONTENT_URI, values)
|
||||
contentResolver.delete(uri, null, null)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
fun Context.isDefaultDialer() = telecomManager.defaultDialerPackage != packageName
|
||||
|
|
|
@ -14,8 +14,8 @@ import com.simplemobiletools.commons.helpers.isMarshmallowPlus
|
|||
import com.simplemobiletools.contacts.pro.activities.EditContactActivity
|
||||
import com.simplemobiletools.contacts.pro.adapters.RecentCallsAdapter
|
||||
import com.simplemobiletools.contacts.pro.extensions.contactClicked
|
||||
import com.simplemobiletools.contacts.pro.extensions.isDefaultDialer
|
||||
import com.simplemobiletools.contacts.pro.extensions.normalizeNumber
|
||||
import com.simplemobiletools.contacts.pro.extensions.telecomManager
|
||||
import com.simplemobiletools.contacts.pro.helpers.IS_FROM_SIMPLE_CONTACTS
|
||||
import com.simplemobiletools.contacts.pro.helpers.KEY_PHONE
|
||||
import com.simplemobiletools.contacts.pro.helpers.RECENTS_TAB_MASK
|
||||
|
@ -28,7 +28,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
|
|||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
override fun placeholderClicked() {
|
||||
if (!isMarshmallowPlus() || (isMarshmallowPlus() && context.telecomManager.defaultDialerPackage == context.packageName)) {
|
||||
if (!isMarshmallowPlus() || (isMarshmallowPlus() && context.isDefaultDialer())) {
|
||||
activity!!.handlePermission(PERMISSION_WRITE_CALL_LOG) {
|
||||
if (it) {
|
||||
activity!!.handlePermission(PERMISSION_READ_CALL_LOG) {
|
||||
|
|
Loading…
Reference in New Issue