Android Question disconnecting a call after 2 rings.

fricentric

Member
Licensed User
Longtime User
hie, i have seen the previous tutorial which Erel had posted about rejecting/disconnecting the call.
https://www.b4x.com/android/forum/threads/end-call-incoming.19714/
i tried using the same code but getting some error. can anyone pls help?

Basically i have to detect an incoming call which is running as a service(whole thing has to run as a service) and get the number. Till here it works fine. That incoming call has to be disconnected after 2 rings. how do you achieve that?

This is the log i get after trying that reject call method

B4X:
LogCat connected to: 2a213eb
--------- beginning of crash
--------- beginning of system
--------- beginning of main
** Service (phdetect) Create **
** Service (phdetect) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (phdetect) Create **
** Service (phdetect) Start **
Error occurred on line: 62 (Main)
java.lang.SecurityException: Neither user 10141 nor current process has android.permission.CALL_PHONE.
    at android.os.Parcel.readException(Parcel.java:1546)
    at android.os.Parcel.readException(Parcel.java:1499)
    at com.android.internal.telephony.ITelephony$Stub$Proxy.endCall(ITelephony.java:1384)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
    at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod(Reflection.java:802)
    at com.nma.incomingph.main._toastphn(main.java:494)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA$2.run(BA.java:328)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5292)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (phdetect) Create **
** Service (phdetect) Start **

line 62 is the last line of the killCall sub of the above shared link.
"r.RunMethod("endCall")"

thanks in advance.
 

Ohanian

Active Member
Licensed User
Longtime User
hi,
add this permission :
android.permission.CALL_PHONE
 
Upvote 0

fricentric

Member
Licensed User
Longtime User
i added that permission but still i get the above error. Strange thing is after running the project, the permission disappears from the manifest file.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
did you try to add
B4X:
AddPermission(android.permission.CALL_PHONE) ' Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.
to the manifesteditor?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Not really.
Maybe sometime it is needed to do it a similar way.

But usually you need to set the permissions listed here in the way i posted in #4 (adding the line(s) to the manifest editor)

Note the manifest is created NEW each time you compile your app. It will be recreated based on the code in the manifesteditor.

So. Add the permission in the way i posted in #4 and try again please.
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
In older versions of B4A, the manifest had to be write protected... The manifest was edited as a "normal" text file, and the permissions were not automatically set. So when the manifest file was edited, there was an option to "do not overwrite" the edited file...
So, in this case... Which B4A version are you using?
 
Upvote 0

fricentric

Member
Licensed User
Longtime User
Not really.
Maybe sometime it is needed to do it a similar way.

But usually you need to set the permissions listed here in the way i posted in #4 (adding the line(s) to the manifest editor)

Note the manifest is created NEW each time you compile your app. It will be recreated based on the code in the manifesteditor.

So. Add the permission in the way i posted in #4 and try again please.



i added the permission the way you said but the same thing is repeated.
 

Attachments

  • manifest1.PNG
    manifest1.PNG
    41.3 KB · Views: 190
Upvote 0

fricentric

Member
Licensed User
Longtime User
In older versions of B4A, the manifest had to be write protected... The manifest was edited as a "normal" text file, and the permissions were not automatically set. So when the manifest file was edited, there was an option to "do not overwrite" the edited file...
So, in this case... Which B4A version are you using?



version of b4a m using is 6.50
 
Upvote 0
Top