我只想检测呼叫在哪里被接受。在可穿戴设备或手持设备上。也就是说,Person_A调用了Person_B,而Person_B有一个可穿戴设备。我希望能够检测到Person_B是否通过他们的可穿戴设备或手持设备接受了电话。
有没有办法在手持设备上检测到这个。
或
有没有办法监听电话,也就是可穿戴设备的PhoneStateLister?
发布于 2014-08-20 23:39:27
您不能直接从wear查询PhoneStateListener,但您可以有一个电话应用程序,当状态更改时,它会向Wear应用程序发送wear Message API。
发布于 2015-07-12 18:31:21
我的答案不会完全解决你的问题,但我想出了如何检测电话在手表上被应答的事实(在我的情况下也是如此)。我通过com.google.android.clockwork.home.incomingcall.PhoneActivity标准活动的存在/缺失来检测它。
代码:
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;
}当然,您应该在单独的线程中使用它。要检测来电是传入、传出还是未接,我使用了the code from this answer.
希望这能帮助到一些人。
https://stackoverflow.com/questions/25200224
复制相似问题