I have found code to programatically block phone calls in Android here, and the following code works:
val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val m1 = telephonyManager::class.java.getDeclaredMethod("getITelephony")
m1.isAccessible = true
val telephonyService = m1.invoke(telephonyManager)
val m2 = telephonyService::class.java.getDeclaredMethod("silenceRinger")
val m3 = telephonyService::class.java.getDeclaredMethod("endCall")
m2.invoke(telephonyService)
m3.invoke(telephonyService)
However, the above code blocks all subsequent phone calls until the device is restarted on API 26 and 25. All other posts on Stackoverflow give a similar solution to this.
Is there a solution for Android before API 28 that just blocks the current phone call?
Aucun commentaire:
Enregistrer un commentaire