默认phone通话 - 如何在通话中select号码服务?
Default phone call - How to select a number service during a call?
我正在进行 默认 phone 调用。一切正常,直到我打电话给总机接线员。
在这种调用中,phone表示:"Press 1 to do A, press 2 to do B"。
我做了几个小时的研究,但找不到...
我确实尝试过此代码,但它不起作用。
keyPressed(KeyEvent.KEYCODE_1); // when press key 1
private void keyPressed(int keyCode) {
....
Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + keyCode));
startActivity(I);
....
playTone(ToneGenerator.TONE_DTMF_1, TONE_LENGTH_INFINITE);
}
非常感谢您的任何建议!
已添加 1 个:
我正在这样使用 InCallService:
class CallService : InCallService() {
private var isShowEnded = true
override fun onCallAdded(call: Call) {
super.onCallAdded(call)
OngoingCall().setCall(call)
CallActivity.getInstance().start(this, call)
isShowEnded = false
}
override fun onCallRemoved(call: Call) {
super.onCallRemoved(call)
OngoingCall().setCall(null)
}
}
和 OngoingCall:
public class OngoingCall {
public static BehaviorSubject<Integer> state = BehaviorSubject.create();
private static Call sCall;
public Call getsCall() {
return sCall;
}
@RequiresApi(api = Build.VERSION_CODES.M)
private Object callback = new Call.Callback() {
@Override
public void onStateChanged(Call call, int newState) {
super.onStateChanged(call, newState);
state.onNext(newState);
}
};
@RequiresApi(api = Build.VERSION_CODES.M)
public final void setCall(@Nullable Call value) {
if (sCall != null) {
sCall.unregisterCallback((Call.Callback) callback);
}
if (value != null) {
value.registerCallback((Call.Callback) callback);
state.onNext(value.getState());
}
sCall = value;
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void answer() {
if (sCall != null) {
assert sCall != null;
sCall.answer(VideoProfile.STATE_AUDIO_ONLY);
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void hold(boolean hold) {
if (sCall != null) {
if (hold) sCall.hold();
else sCall.unhold();
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void addCall(Call call) {
if (sCall != null) {
sCall.conference(call);
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void hangup() {
if (sCall != null) {
sCall.disconnect();
}
}
}
然后我在按下键盘时尝试了这个:
mTrueCallerOngoingCall.getsCall().playDtmfTone((char) tone); // inside playTone()
但是还是不行:(
更新二:
我已经修复了添加此方法的问题:
private char getChar(int tone) {
if (tone == 0) return '0';
else if (tone == 1) return '1';
else if (tone == 2) return '2';
else if (tone == 3) return '3';
else if (tone == 4) return '4';
else if (tone == 5) return '5';
else if (tone == 6) return '6';
else if (tone == 7) return '7';
else if (tone == 8) return '8';
else if (tone == 9) return '9';
else if (tone == 10) return '*';
else return '#';
}
并将我上面的代码更改为
mTrueCallerOngoingCall.getsCall().playDtmfTone(getChar(tone));
mTrueCallerOngoingCall.getsCall().stopDtmfTone();
是。希望能帮到你。
call.playDtmfTone(char);
调用路径:
android.telecom.Call;
发件人:任何 Class 扩展 InCallService。
在方法中:onCallAdded(call);
我正在进行 默认 phone 调用。一切正常,直到我打电话给总机接线员。
在这种调用中,phone表示:"Press 1 to do A, press 2 to do B"。
我做了几个小时的研究,但找不到... 我确实尝试过此代码,但它不起作用。
keyPressed(KeyEvent.KEYCODE_1); // when press key 1
private void keyPressed(int keyCode) {
....
Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel://" + keyCode));
startActivity(I);
....
playTone(ToneGenerator.TONE_DTMF_1, TONE_LENGTH_INFINITE);
}
非常感谢您的任何建议!
已添加 1 个: 我正在这样使用 InCallService:
class CallService : InCallService() {
private var isShowEnded = true
override fun onCallAdded(call: Call) {
super.onCallAdded(call)
OngoingCall().setCall(call)
CallActivity.getInstance().start(this, call)
isShowEnded = false
}
override fun onCallRemoved(call: Call) {
super.onCallRemoved(call)
OngoingCall().setCall(null)
}
}
和 OngoingCall:
public class OngoingCall {
public static BehaviorSubject<Integer> state = BehaviorSubject.create();
private static Call sCall;
public Call getsCall() {
return sCall;
}
@RequiresApi(api = Build.VERSION_CODES.M)
private Object callback = new Call.Callback() {
@Override
public void onStateChanged(Call call, int newState) {
super.onStateChanged(call, newState);
state.onNext(newState);
}
};
@RequiresApi(api = Build.VERSION_CODES.M)
public final void setCall(@Nullable Call value) {
if (sCall != null) {
sCall.unregisterCallback((Call.Callback) callback);
}
if (value != null) {
value.registerCallback((Call.Callback) callback);
state.onNext(value.getState());
}
sCall = value;
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void answer() {
if (sCall != null) {
assert sCall != null;
sCall.answer(VideoProfile.STATE_AUDIO_ONLY);
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void hold(boolean hold) {
if (sCall != null) {
if (hold) sCall.hold();
else sCall.unhold();
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void addCall(Call call) {
if (sCall != null) {
sCall.conference(call);
}
}
@RequiresApi(api = Build.VERSION_CODES.M)
public void hangup() {
if (sCall != null) {
sCall.disconnect();
}
}
}
然后我在按下键盘时尝试了这个:
mTrueCallerOngoingCall.getsCall().playDtmfTone((char) tone); // inside playTone()
但是还是不行:(
更新二: 我已经修复了添加此方法的问题:
private char getChar(int tone) {
if (tone == 0) return '0';
else if (tone == 1) return '1';
else if (tone == 2) return '2';
else if (tone == 3) return '3';
else if (tone == 4) return '4';
else if (tone == 5) return '5';
else if (tone == 6) return '6';
else if (tone == 7) return '7';
else if (tone == 8) return '8';
else if (tone == 9) return '9';
else if (tone == 10) return '*';
else return '#';
}
并将我上面的代码更改为
mTrueCallerOngoingCall.getsCall().playDtmfTone(getChar(tone));
mTrueCallerOngoingCall.getsCall().stopDtmfTone();
是。希望能帮到你。
call.playDtmfTone(char);
调用路径:
android.telecom.Call;
发件人:任何 Class 扩展 InCallService。
在方法中:onCallAdded(call);