Android Question Caller Phone Number when app is run during call

LMASTER

Member
Licensed User
Longtime User
Hi, I have read the posts that follow...
https://www.b4x.com/android/forum/threads/android-permissions.77304/#content
call.zip

https://www.b4x.com/android/forum/threads/incomingnumber-in-the-background.43543/
caller ID.zip

https://www.b4x.com/android/forum/threads/get-the-number-of-the-current-caller.11960/#post-581116
(missing Main type)

The first one lists the last phone number, but not the current one.
The second List the calling number if the call occurs while the app is running.
The third I have not been able to run (not sure how to get Main type)

What I am hoping to find out, is how to get a process in the following case...

Phone Rings, during the call the app is opened to enter information, and the
phone number and caller ID if any are already there in a text box.
Please let me know if this is possible, and if anyone has a sample.

Thanks for your help, I am an old VB6 programmer, trying out B4a
as an alternative to trying to learn something else.
 

MarkusR

Well-Known Member
Licensed User
Longtime User
(missing Main type)
it just memory something into a variable, i guess in main activity
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i did not tested but try this in main activity.
this service make a test if this LastInNumberContact is null. maybe this main activity save something there after open activity.
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Public PhoneState As String
    Public LastInNumber As String
    Public LastInNumberContact As Object
    
End Sub
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
Thanks for you help, I guess you are working with the third example above, after trying it out, I see it has the same problem...
The service only triggers when the phone state changes (as when a call is received).
But that will not help, because the call is already ongoing when the app is started.

Imagine you are a Nurse and receive a phone call
You realize its a patient, then Launch the Android Application, and check a few boxes regarding the call...

but the name of the caller and his or her phone number is already on the App (this is what I need to do)
So you don't have to enter it later.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
yes, just spoke about the 3 example.
its a service, if you make a foreground/background service me thougth the activity pop up at incoming call with the caller number.
why u need start the app only at the call and not before? if you hide the activity the service still run.
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
The way the app works its for a Nurse that is "on call" so they go about the duties of the day, taking care of patients, etc. suddenly they get a phone call, during the call they realize its Doctor A's patient, so they open the application and selects Doctor A, adds a few notes and a report is generated. If it was doctor B then they select Doctor B and another report is made. Currently they have to add the phone number and name manually, I was hoping to help speed things up.
And of course they don't want personal calls to interfere with the application, so it does not run in the background.
Can you help?
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i made a test, if you just open the app if you already speak with someone there is no event that give you the number. only later at hang up.
how about run a service in background but resume a activity (input form) only by click the app icon? the service can memory the last number until the activity opens manually.
for input name or comment i would try voice recognition optional.
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
Thanks for the suggestion, but the app uses mobile data to connect to a server, and is restricted, It's impossible to keep it running
heavy on memory and resources, etc.
There must be a way to get at least the phone number of a live conversation, the Nurses keep complaining and worst of all forgetting to enter the caller phone number, then they spend hours looking at long phone logs to retrieve information that should have been done automatically.
I even tried making the app wait for the phone call to end and then request the info to try to add to the log, but its not automatic
and the log needs this information first.
If anyone has an idea, please let me know
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
Thanks Erel,
Seems to be a method of intercepting the hang up, so the app can then retrieve the caller ID and report...
I was hoping to get the Caller ID during the call (without running the app all day), but it seems to be too much to ask from B4a.

if anyone comes up with that, please let me know.
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
Thanks Erel and Moster67

That is however the problem, the only way this would work is if we had a separate phone used only for those calls that need to be processed.
I cant get a single client to agree with that, they want the app to run after the call is received, if in the conversation they realize its a call that needs to be logged and processed, but if the call comes from Mom or a friend, they don't want the app running.
I think the ratio is 30 personal or no need for the app calls for 1 call that requires the app, and there is no way to try to identify which is which, the patient may be calling from a different number, I hope you understand.

Maybe we need to focus on not using a service, there is no need, all we need is to somehow retrieve the live information of the current caller, but there is no need to trigger an event.
Currently I have it running and the program waits for the call to end, after that the Caller info becomes available, but the user does not benefit of having the app review that info during the call.

Thanks to all for your help, hope something comes up and we will all learn from it.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Well, as far I know, if you want Android (and its APIs) to give you the phone number of any incoming call, there must be a service running (perhaps as a Sticky one). The user needs to enter/register in your app only working related phone numbers (or you as a developer put them in) and then you can distinguish the incoming calls in question from friends etc.

The other way, is to consult the CallLogs (see the phone-library) which you can filter for incoming calls but I believe the calls themselves get registered in the logs only once a phone call has been terminated so that is probably not what you need unless it is acceptable for you that the user can open your app after a phone call has ended and then your app retrieve the last phone call and its number and you associate it with a certain person....

I don't think that there are any other options (and as Erel said, it is not B4A related) - this is what Android has to offer.

On the other hand, why an app should not be running all day (as I said perhaps as a sticky service) is really an Android user thing and task-manager related. It is not really that strange; look at iPhones and iOS in general (where no services or background tasks are available unless the app is of a particular type such as a Voice Over IP) - the apps work very well. I, for instance, never kill my running apps.
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
Thanks Moster67,
Yes, I see the problem, and I am retrieving the information after hangup, for now, when I try to explain to the user that the info is only available after the call ends, the look at me with a (it doesn't make sense look). And if I ask them to run a service each time they use their personal phones, they look at me with a (why do you want to collect my personal call info, look).

Personally I just think it takes the left hand talking to the right hand (You know one part of the phone talking with the other) and I can think of
a million uses an good app could satisfy if it could process information during a call.
As phones are becoming part of daily life, people expect them to do more, and that may be what this post is about.
Maybe our wonderful phone library could come up with a LIVE_CALL event in the future?
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Maybe our wonderful phone library could come up with a LIVE_CALL event in the future?
Does Android offer such a feature? I don't think so and therefore B4A cannot offer it. If you need it, you need to talk to Google and their Android team :)

Still, I am pretty sure your users can accept an app with a background service running, only popping up an activity or a notification when they are receiving a call from a pre-designed phone number, especially if they will benefit from it. If not, they should not be using WhatsApp, Facebook too...

Good luck with your app!
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
Exactly! the problem is the calls don't come from pre-designed phone numbers, to clarify these are used by Nurses in a Psych facility...
there are 30 that all have cell phones, they share the patient list and take turns being on call, the issues have been that all these calls need to be followed up by a record and in some cases action by the team leader or doctor must be taken.
With my app for example; Nurse Sally gets a phone call at 2:15am from 714 5551212, If the app where able to pull caller info, she would be ahead of the situation, recognizing the caller and offer assistance in a more personalized way...
Currently due to the above mentioned "Android Limitation" she has to run the caller through 50 questions before she can Guess at a recommendation, then the call ends, and the App lets her know all she had to do is offer to refill the patients prescription, she hits redial to call back the patient and the line is busy as the patient is initiating a new call to the Doctor's office.
I used to provide the service on portable pocketPC phones, but Android Won that little war.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi @LMASTER , out of curiosity: why is to be considered "intrusive" an app that pops up on a call showing a simple "dismiss" button along with a "more details" one?
When a nurse receives a call from home she can hit Dismiss and forget about the app. In case of a patient, hitting "more details" will open up a form (or whatever) giving her all the details and operational options.
Recoding a list of "known numbers" (home, mom,dad, husband..) will ease the pop-up stage, but will not be a fundamental part of the app; just an option the user could use or not to limit the numebr of times is required of an action.
 
Upvote 0

LMASTER

Member
Licensed User
Longtime User
Hi udg
I wonder if there is a possibility of running a service separate from my app that records the call when received and saves it to a file.
Then my app could read that file even if the call is ongoing.
So lets say we call it UDGCallerID, all that service would do is record the last incoming call and save a file in local storage called CallerID.txt
The file would get written over for every new call.
My app could be closed, and when the Nurse gets the call she would open the app, and it would look for the file and load up with the information.
Anyone willing to make the CallerID app or modify one of the prior samples to fit?

That app could be distributed in Google Play to anyone, and I could simply suggest they add it if they want the program to have the information up front.
 
Upvote 0
Top