gpt4 book ai didi

java - 如何检测已接电话?

转载 作者:太空宇宙 更新时间:2023-11-04 10:13:52 26 4
gpt4 key购买 nike

我正在尝试在我的应用程序上成功检测到自动应答的电话。我可以成功检测到振铃调用并应答它,但一旦应答, Activity 状态或摘机状态就不会出现。我以 root 用户身份使用 shell 中的电话服务接听此调用。现在我正在使用 Android 中的 PreciseCallState,但已经尝试使用 TelephonyManagerTelecomManager

我检测并应答来电的类

@VoiceInTaskScope
public class VoiceInPhoneStateListenerSystem extends AbstractVoiceInPhoneStateListener {

private static final String TAG = "VoicePhoneStateListenerSystem: ";

private int mCallFinished = 0;
private int mLastState = 0;

private PhoneStateListenerManager mPhoneStateListenerManager;

@Inject
public VoiceInPhoneStateListenerSystem(@Named(TasksModule.TASKS_CONTEXT) Context context,
TelephonyManager telephonyManager,
PhoneStateListenerManager phoneStateListenerManager,
@Named(VoiceInTaskModule.VOICE_IN_ACTION_CALL_INTENT) Intent actionCallIntent,
TimerWrapper timerWrapper, Sound sound, Provider<CSFBThread> csfbThreadProvider) {
super(context, telephonyManager, actionCallIntent, timerWrapper, sound, csfbThreadProvider);
this.mPhoneStateListenerManager = phoneStateListenerManager;

}

@Override
@CoverageIgnore
public void startListener() {
mPhoneStateListenerManager.listen(this, PhoneStateListener.LISTEN_PRECISE_CALL_STATE);
}

@Override
@CoverageIgnore
public void endListener() {
mPhoneStateListenerManager.listen(this, PhoneStateListener.LISTEN_NONE);
}

/**
* Obtains the precise state of the call
*
* @param callState info of the state
*/
@Override
public void onPreciseCallStateChanged(final PreciseCallState callState) {
final int ringingCallState =callState.getRingingCallState();
final int foregroundState = callState.getForegroundCallState();
final int backgroundState = callState.getBackgroundCallState();
final int disconnectCause = callState.getDisconnectCause()

if ( ringingCallState == PreciseCallState.PRECISE_CALL_STATE_INCOMING){
Log.info(TAG +"answer");
superSu();
}

if( foregroundState == PreciseCallState.PRECISE_CALL_STATE_ACTIVE){
Log.info(TAG + "inside!!!");
this.initTimer();
}
}

接听来电的方法

public static void superSu() {
try {

Process proc = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(proc.getOutputStream());

os.writeBytes("service call phone 5\n");
Thread.currentThread().interrupt();
os.flush();

os.writeBytes("exit\n");
os.flush();

if (proc.waitFor() == 255) {
// TODO handle being declined root access
// 255 is the standard code for being declined root for SU
}
} catch (IOException e) {
// TODO handle I/O going wrong
// this probably means that the device isn't rooted
} catch (InterruptedException e) {
// don't swallow interruptions
Thread.currentThread().interrupt();
}
}

最佳答案

谢谢!!!我所要做的就是关闭 superSu() 方法上的当前线程,就像这样

 public static void superSu() {
try {

Process proc = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(proc.getOutputStream());

os.writeBytes("service call phone 5\n");
os.flush();

os.writeBytes("exit\n");
os.flush();

Thread.currentThread().interrupt();//close current thread

if (proc.waitFor() == 255) {
// TODO handle being declined root access
// 255 is the standard code for being declined root for SU
}
} catch (IOException e) {
// TODO handle I/O going wrong
// this probably means that the device isn't rooted
} catch (InterruptedException e) {
// don't swallow interruptions
Thread.currentThread().interrupt();
}
}

关于java - 如何检测已接电话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51969543/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com