Multiple phone calls from android app - android

I'm implementing a function where an outgoing alarm is triggered, f.e. If the phone falls down and doesn't move for 60s afterwards. Then, between 1-5 numbers should be called. Example of how it should work:
Phone falls down and doesnt move for 60s
Number 1 is called
Number 1 doesn't accept call in 20s
Number 2 is called
Number 2 doesn't accept call in 20s
Number 3 is called
Number 3 accepts call, alarm is being terminated
The alarm is triggered correctly, and I can make a call. But I couldn't find anything on how to determine if a call was accepted after x seconds, and how to start a new call then. Any help / sources?
Edit:
Via the PhoneStateListener I'm now able to see if the call was cancelled. However if it's not, I can't get the actual state, so I don't know if it's still ringing, if it's actually calling or if it has gone to the mailbox. In the description of the CALL_STATE_OFFHOOK it's pretty clear that you can't see wheter the call was answered or the number has just been dialed. Is there any workaround for that, maybe even with rooting the phone or something like that? Any hint is appreciated.

It seems like this isn't possible.
The documentation for Intent.ACTION_CALL states that it doesn't return an output (at least I guess that's what the oh-so-helpful "Output: nothing" comment means).
Similar questions here and here have not gotten any useful positive responses.

While using an intent makes it NOT possible since you can't check the state, that's NOT the way you should call the telephony service since you want your program to be in control. The best way is to this is to:
a) enable telephony permissions in your app:
b) instantiate the Telephony manager class in your activity, then
c) handle Android call states dial/listen in your activity to store the previous state. If it was 'ringing' and current state is idle a they cancelled the call. If the current state is off-hook and the previous state was ringing, they answered the call. See a working sample here:
http://www.compiletimeerror.com/2013/08/android-call-state-listener-example.html

Related

Programmatically detect when outgoing call starts ringback tone (ringing to the other person)

I want to know how to detect in android when an outgoing call is acceptable (but not yet accepted) by the other person and you receive the ringback tone.
I tried PhoneStateListener using method onCallStateChanged(int state, String callingNumber), but the state only returns to me 2 (starts) and 0 (ends) and not when the call is acceptable by the other person (There is a time between you starts the call and the other phone receive the call and starts to ring)
There already are an android method to know it or what to do?
According to your question my answer is No
There is NO way (sadly, because I need it) to detect the time of an outgoing call starts ringing.
It's impossible to detect by regular non-system application - no Android API. I could not find a way, I was googling the solution within very long time :-(

Is there a way to explicitly control WiFi scan intervals in Android?

I am doing my Master thesis at the moment on WiFi positioning and in order to test my algorithms I needed to collect some data.
To do this I have written a short and very simple program for Android which simply collects the RSSI for all availible access points found by each scan and saves them to file. I have set up a BroadcastReceiver that listens on the event WifiManager.SCAN_RESULTS_AVAILABLE_ACTION and I use a Timer, here called tim, to initiate scans with a WifiManager, called wifi as follows:
tim.schedule(new TimerTask(){
#Override
public void run(){
wifi.startScan();
}
}, 0, 1000);
The problem I am having now is that the initiated scans don't seem to happen every second even if I succeed in initiating them and every now and then there are other scans initiated from some other app that gets recorded as well.
Is there any easy way to scan on a set interval and not receive the scans initiated by some other app?
The whole app can be found on https://github.com/while/RSSIMiner if it helps in any way.
Is there any easy way to scan on a set interval?
If this doesn't work well, I'm afraid not. From my experience, "hardware related" methods may not work exactly like their definition says. For example, I once created a small app which records your position every X minutes. So I call requestLocationUpdates with some minTime parameter. But my phone simply ignores the minTime value, and I get updates from the GPS as soon as they're available, whcih is not what I wanted. I posted a question about it here, and got this answer, from which we learn that prior to jelly bean, devices may simply ignore this value...
So it may be something similar now. I'd try to run this code on the latest Android version. And I don't understand that much in Wifi, but isn't 1 second a too frequent interval for scans? Perhaps the system doesn't ignore the scan request (So it returns true) but the hardware does?
Can we ignore the scans initiated by some other app?
As far as I know, it's negative here too. There are no extras contained in the SCAN_RESULTS_AVAILABLE_ACTION broadcast so you can't know which app initiated the scan.
The best solution will be to defnie your requirements. You can use the ScanResult.timestamp to determine if you should use this result or not. For example, if you're trying to get the RSSI for each access point each second, you can compare the current BSSID to previous BSSIDs. If the current BSSID was included in a scan result from the last second, you can simply ignore it. Then, it doesn't matter how many results you get.
Another, much more simple soltuion will be to create a boolean called scanInitiated and set it to true when starting a scan. When receiving the broacast, use the data only if scanInitiated is true, and then set it to false. This isn't so reliable when the intervals are short, but for long intervals it will work great.

How to know that the dialled number has received a ring?

My app requires to know whether the other party has recived my call or not. I need to execute some logic after 1 or 2 rings.
To do this I have overridden onCallStateChanged method, and check for CALL_STATE_RINGING state. But it looks like this method is not 100% perfect since it takes some time for the ring to happen after the state changes to CALL_STATE_RINGING.
Any suggestions on how to go ahead with the implementation? One approach is to have some delay of 2 to 3 seconds after the state changes to CALL_STATE_RINGING. But this approach is really dumb since the delay will vary between telcos. Any other ideas?
Not sure if is possible to detect when the other party picked up, still i think this link can be useful to you
How do I get state of a outgoing call in android phone?

Is there a Dropped Call Listener

Does the Android SDK have the ability to to trap a Dropped Call event? If so, what is it called? I've been prowling the documentation looking for it.
Is there a difference between a hang up, and a dropped call?
Does the Android SDK have the ability
to to trap a Dropped Call event?
No.
Is there a difference between a hang
up, and a dropped call?
To humans, yes. To Android, no.
Just a bit of additional information.
The Android system does know when a call is dropped for what ever reason, i.e. Congestion, No Circuit Available etc. However none of this information is parsed through to the sdk. In the source at some point android basically mashes a whole bunch of telephony related information into a few, excruciatingly vague sdk calls. For example - the only indication we get of a call end is the changed in a PhoneStateListener from OffHook to Idle. Which literally encompasses every single reason for a call ending.
Even different states of the call are mashed together. Where as we should be able to get information like whether the phone is alerting the b party or actually has an active connection, this is reduced to the three states available, offhook, idle and ringing - note ringing is only when your device is ringing, not when the person you are calling phone's ring.
Sorry to be another bearer of bad new, but alas. all we can hope for is better support at a later stage

How can I detect when outgoing call has been accepted

I am not able to detect when outgoing call has been answered, I have registered BroadcastReceiver for PHONE_STATE broadcast, but onReceive() gets called only when number is dialed and when call has ended.
Edit: If it is not possible with current API (1.5 or 1.6) please enlighten me ?
Android does not have specific listener yet for making sure whether the call(outgoing call) is answered or not. The moment a number is dialled it goes to off_hook state (in case of outgoing call). This is one one of the gap which android telephony has to yet come up with
I don't see you getting any specific answers, so I try with a general one that may help. If you are referring to calls going out the PSTN (Public switched telephone network), you won't be able to detect when the far side answers. The way the phone network is structured, you won't be able to get that information except in very special cases. Usually what you see on the handset is the moment the call is being routed out of the cell network.
As for in network (same subscriber), it may be possible to get that information, but I'm not sure. You may want to look into CDMA or the protocol used by your carrier to see if it is going to even be possible to get farside information.

Categories

Resources