Reputation: 368
I'm thinking in an application to send/receive a Morse-like short message as follow:
- phone rings 1 --> "."
- phone rings 2 times --> "_"
or: (if the previous method is impossible)
- phone rings for 1 second --> "."
- phone rings for 2 seconds --> "_"
It is there a way to know how many times the phone rings when I start a call programmatically?
I would like to know how many times it is played the sound that we hear when we call other people (and, for example, stop calling after phone rings 2 times) (please note that this approach needs to know this info for outgoing calls and for incoming calls, so the application can decode the received message)
If the previous method isn't possible: is possible to, at least, track how many seconds is the phone ringing? (when we are calling someone, it most to start counting when we hear the first ring)
Thanks in advance.
Upvotes: 0
Views: 1833
Reputation: 5600
I don't know if is possible detect how many times phone rings, but you can know how much time takes to answer, so just need the seconds and calculate the time to know how many times ring. Use a receiver.
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
callTime = System.currentTimeMillis();
}else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK){
answeredTime = System.currentTimeMillis();
timeTaken = answeredTime - callTime;
}else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
}
}
}
Upvotes: 1