Android Question EndCall routine does not work on Android 8.x !?

palmzac

Active Member
Licensed User
Longtime User
Hi,

This routine is work perfectly before Android 8.x. The MODIFY_PHONE_STATE permission already put into manifest editor. Would you help me to solve this problem ? Thanks !

B4X:
Dim r As Reflector
r.Target = r.GetContext
Dim TelephonyManager, TelephonyInterface As Object
TelephonyManager = r.RunMethod2("getSystemService", "phone", "java.lang.String")
r.Target = TelephonyManager
TelephonyInterface = r.RunMethod("getITelephony")
r.Target = TelephonyInterface
r.RunMethod("endCall")

This is error message on Android 8.x .
java.lang.SecurityException: MODIFY_PHONE_STATE permission required.
at android.os.Parcel.readException(Parcel.java:2005)
at android.os.Parcel.readException(Parcel.java:1951)
at com.android.internal.telephony.ITelephony$Stub$Proxy.endCall(ITelephony.java:2027)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:802)
at com.hkcorp.b4a.qehkfilter.joblistener._killcallnow(joblistener.java:910)
at com.hkcorp.b4a.qehkfilter.joblistener._killcall(joblistener.java:882)
at com.hkcorp.b4a.qehkfilter.joblistener._handlecall(joblistener.java:709)
at com.hkcorp.b4a.qehkfilter.joblistener._pe_phonestatechanged(joblistener.java:1296)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.phone.PhoneEvents$ActionHandler.send(PhoneEvents.java:326)
at anywheresoftware.b4a.phone.PhoneEvents$15.handle(PhoneEvents.java:245)
at anywheresoftware.b4a.phone.PhoneEvents$16.onReceive(PhoneEvents.java:268)
at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$-android_app_LoadedApk$ReceiverDispatcher$Args_52497(LoadedApk.java:1313)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.$m$7(Unknown Source:4)
at android.app.-$Lambda$aS31cHIhRx41653CMnd4gZqshIQ.run(Unknown Source:39)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 

DonManfred

Expert
Licensed User
Longtime User
java.lang.SecurityException: MODIFY_PHONE_STATE permission required.

I guess you have set targetsdk to 26.
Are you using Runtimepermissions and request the right permission?
 
Upvote 0

palmzac

Active Member
Licensed User
Longtime User
Hi DonManfred,

Thank for your reply !

MODIFY_PHONE_STATE permission does not need Runtimepermissions After I check the B4A permission tool.

test1.png


java.lang.SecurityException: MODIFY_PHONE_STATE permission required.

I guess you have set targetsdk to 26.
Are you using Runtimepermissions and request the right permission?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

palmzac

Active Member
Licensed User
Longtime User
:eek:
I used the EndCall routine on my project. How to simulate it on Android 8.x ? Would you help me ?

my manifest
test2.png

https://developer.android.com/reference/android/Manifest.permission#MODIFY_PHONE_STATE

MODIFY_PHONE_STATE
added in API level 1
public static final String MODIFY_PHONE_STATE
Allows modification of the telephony state - power on, mmi, etc. Does not include placing calls.

Not for use by third-party applications.

Constant Value: "android.permission.MODIFY_PHONE_STATE
 
Upvote 0

palmzac

Active Member
Licensed User
Longtime User
Hi Erel,

Thank for you reply ! I know that. :confused:

I want to find a alternative.

I found this code on Stackoverflow. How to convert it to B4A code ? Is it possiable ?

B4X:
    TelecomManager tm = (TelecomManager)  context.getSystemService(context.TELECOM_SERVICE);

    if (tm != null) {
        boolean success = tm.endCall();
        // Call was terminated or not.
    }



It will not work. Your app will never have the MODIFY_PHONE_STATE permission.
 
Upvote 0

palmzac

Active Member
Licensed User
Longtime User
Hi Erel,

Thank for your quick reply ! :)

Let me try.

B4X:
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim tm As JavaObject = ctxt.RunMethod("getSystemService", Array("telecom"))
Dim success As Boolean = tm.RunMethod("endCall", Null))
 
Upvote 0
Top