Reputation: 1284
How do detect the time when a phone starts ringing for outgoing calls. I am developing an Application in which I am trying to make a call programatically and when call is connected (ringing). I want get back some response(Like connected). I am trying below code, its able to make call but don't know how to get response.
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"mobile no."));
startActivity(callIntent);
Thanks in advance for your time and consideration.
Edit : When outgoing call is connect (Ringing state) then i want get back a notification. like a toast or anything else which is relevant. is it possible?
Upvotes: 4
Views: 2346
Reputation: 63
I know its been a while but i hope to be helpful for someone still looking for a solution!
I recently had to work on a similar project where i needed to capture the ringing state of an outgoing call and the only way i could find was using the hidden Api of native dial-up App. This would only be possible for android > 5.0 because of the api changes. This was tested on Android 5.0.1, and worked like a charm. (p.s. you would need a rooted device for it to work, because you need to install your app as a System application (google how!) which will then be able to detect the outgoing call states).
For the record, PhoneStateListener doesn't work for detecting the outgoing call states as mentioned in many posts.
First, add this permission in the manifest file,
<uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />
Then define you broadcastreceiver, (here is a sample code!)
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
public class MyBroadcastReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, final Intent intent)
{
switch (intent.getIntExtra("foreground_state", -2)) {
case 0: // PreciseCallState.PRECISE_CALL_STATE_IDLE:
System.out.println("IDLE");
break;
case 3: // PreciseCallState.PRECISE_CALL_STATE_DIALING:
System.out.println("DIALING");
break;
case 4: // PreciseCallState.PRECISE_CALL_STATE_ALERTING:
System.out.println("ALERTING");
break;
case 1: // PreciseCallState.PRECISE_CALL_STATE_ACTIVE:
System.out.println("ACTIVE");
break;
}
}
}
I replaced some of the constants with their values because I saw a lot of confusion among the folks unfamiliar with the concept of reflection (for ease). Alerting is basically the state when receiver is actually ringing! and that does not include the call setup time! so you can get the time in that case statement by using,
System.currentTimeMillis();
or some other format you would prefer!
Upvotes: 2
Reputation: 1065
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 :-(
There is NO way (sadly, because I need it) to detect the time of an outgoing call starts ringing.
Upvotes: -1
Reputation: 7081
You will have to use a BroadcastReceiver to listen for the call event and then handle it when it gets fired. Here is a nice tutorial I found on Google.
Upvotes: 1