简体   繁体   中英

Android : Phone call detect when connected?

I can use this code to make outgoing call:

Intent dial = new Intent(Intent.ACTION_CALL); 
dial.setData(Uri.parse("tel:5556") ); 
context.startActivity(dial);

But how to detect whether the call is picked up or the call is refused? I tried PhoneStateListener, but it is not working.

Unfortunately, Android gives no mean to know when an outgoing call has been answered.

PhoneStateListener works fine but the 3 states notified by onCallStateChanged are not enough. An additional state like CALL_STATE_CONNECTED would be welcome.

There is an open issue requesting this feature but it didn't get much attention so far: https://code.google.com/p/android/issues/detail?id=14266

Some people (like me) falls back using logcat and tries to infer if an outgoing call has been answered but this is far from an ideal solution.

I am also searching for an answer to the same problem, apparently no straight forward method is present to do this. But, I think we can combine a Call Log content observer with PhoneStateListener to get the call duration. We could set a flag in the shared prefs when an outgoing call is started, if anything changes in call log and our shared prefs flag is true we could get the call duration from the call log to see if the call was ever connected :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM