Skip to content

Commit dab3c58

Browse files
committed
handle CALL_PHONE permission at initiating a call
1 parent 638af17 commit dab3c58

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
1010
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
1111
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
12+
<uses-permission android:name="android.permission.CALL_PHONE"/>
1213

1314
<uses-permission
1415
android:name="android.permission.WRITE_EXTERNAL_STORAGE"

app/src/main/kotlin/com/simplemobiletools/contacts/pro/extensions/Activity.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.net.Uri
55
import com.simplemobiletools.commons.activities.BaseSimpleActivity
66
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
77
import com.simplemobiletools.commons.extensions.*
8+
import com.simplemobiletools.commons.helpers.PERMISSION_CALL_PHONE
89
import com.simplemobiletools.commons.models.RadioItem
910
import com.simplemobiletools.contacts.pro.BuildConfig
1011
import com.simplemobiletools.contacts.pro.R
@@ -14,14 +15,16 @@ import com.simplemobiletools.contacts.pro.helpers.*
1415
import com.simplemobiletools.contacts.pro.models.Contact
1516

1617
fun SimpleActivity.startCallIntent(recipient: String) {
17-
val action = Intent.ACTION_CALL
18-
Intent(action).apply {
19-
data = Uri.fromParts("tel", recipient, null)
18+
handlePermission(PERMISSION_CALL_PHONE) {
19+
val action = if (it) Intent.ACTION_CALL else Intent.ACTION_DIAL
20+
Intent(action).apply {
21+
data = Uri.fromParts("tel", recipient, null)
2022

21-
if (resolveActivity(packageManager) != null) {
22-
startActivity(this)
23-
} else {
24-
toast(R.string.no_app_found)
23+
if (resolveActivity(packageManager) != null) {
24+
startActivity(this)
25+
} else {
26+
toast(R.string.no_app_found)
27+
}
2528
}
2629
}
2730
}

0 commit comments

Comments
 (0)