转载请以链接形式标明出处: 本文出自:103style的博客
最后的判断代码:
/**
* 是否正在电话通话中
*/
private boolean phoneIsInUse() {
TelephonyManager mTelephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
int state = mTelephonyManager.getCallState();
return state != TelephonyManager.CALL_STATE_IDLE;
}
开始在网上搜了搜,找到下面这两个:
然后 却找不到 ITelephony
类了。
private boolean phoneIsInUse() {
boolean phoneInUse = false;
try {
ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
if (phone != null) phoneInUse = !phone.isIdle();
} catch (RemoteException e) {
Log.w(TAG, "phone.isIdle() failed", e);
}
return phoneInUse;
}
6.0
之后才可以用这个, 且需要判断 READ_PHONE_STATE
权限.
public static boolean phoneIsInUse(Context context){
TelecomManager tm = (TelecomManager)context.getSystemService(Context.TELECOM_SERVICE);
return tm.isInCall();
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有