1

I would simply like to detect where a call has been accepted. On the Wearable, or the Handheld. i.e Person_A calls Person_B and Person_B has a wearable device. I would like to be able to detect if Person_B accepted the cal via their wearable device, or their handheld.

Is there a way of detecting this on the handheld.

OR

Is there a way to listen for calls i.e. a PhoneStateLister for wearable?

2 Answers2

0

You cannot query the PhoneStateListener directly from wear but you could have a phone application that sends a Wear Message API to a wear application when the state changes.

CodeChimp
  • 4,745
  • 6
  • 45
  • 61
  • Cheers, i was thinking this but when the native android phone is ringing, which means the corresponding wear is also vibrating (allowing the user to answer or decline the call) how would i place my app on the wear to effectively say "dont use the default android wear to answer a call, use my app instead"? – Leatherface1877 Aug 20 '14 at 17:38
  • I keep thinking, there must be away that my wearable app could listen on the wearable to say, "An incoming call has been answered or declined". I am aware i can use the PhoneStaeListenr on the handheld phone device, and i can detect if someone is ringing or accepted or hung up the call from the phone device app, but it does not tell me where from (i.e was the call accepted from the device or the wearable) – Leatherface1877 Aug 20 '14 at 17:46
  • I'm not sure if you can replace the wear app to answer a call. Sounds like what you'd need to do though if you wanted to detect it being answered on wear rather than phone. – CodeChimp Aug 21 '14 at 07:12
0

My answer will not solve the whole your problem, but I figured out how to detect the fact that call was answered on the watch (and it works in my case). I detect it by presence/absence of the com.google.android.clockwork.home.incomingcall.PhoneActivity standard activity.

The code:

void waitForAnswer() {
 sleep(1000, 0); // give a chance to the standard ringing activity
 while (!isPhoneAnswered())
    Thread.sleep(1000, 0);
 // Here the call is anwered but you can not tell is it answered on the phone or on the watch or simple missed
}

private boolean isPhoneAnswered() {
    boolean result = true;
    try {
        final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final List<ActivityManager.RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

        for (int i = 0; i < recentTasks.size(); i++) {
            if (recentTasks.get(i).topActivity.getClassName().contains("com.google.android.clockwork.home.incomingcall.PhoneActivity")) {
                result = false;
                break;
            }
        }
    } catch (Exception ex) {
        Log.e(Constants.AppName, ex.getMessage());
    }

    return result;
}

Of course you should use it in a separate thread. To detect is call incoming, outgoing or missed I use the code from this answer.

Hope this will help somebody.

Community
  • 1
  • 1
Alexandr
  • 695
  • 2
  • 9
  • 18