I tried to call the phone intent on Kotlin, like this:
imgPhone.setOnClick {
val intent = Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "1122334455"))
startActivity(intent)
}
When the phone image is clicked, nothing visually happens. Turns out the debugger showed you this:
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity }
I've tried several solutions:
- Put this line in AndroidManifest.xml:
< uses-permission android:name="android.permission.CALL_PHONE"/>
Add android:exported="true" at the activity on which the call intent is invoked:
< activity android:name=".activities.ProfileActivity" android:exported="true"/>
Ask permission explicitely:
override fun onCreate() { super.onCreate() /* more codes here */ setupPermissions() } fun setupPermissions() { val permission = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) if (permission != PackageManager.PERMISSION_GRANTED) { Log.i("Error", "Permission to call denied") } }
So far, none of those workarounds work (on Android 6). The same SecurityException still occurs. What is the proper solution, then?