【发布时间】:2019-01-21 07:36:32
【问题描述】:
我想在通话过程中检查拨号盘是否被激活。我正在构思一个简单的应用程序,它需要在通话过程中知道拨号盘的状态。
任何代码 sn-p 或指向 tuts 的链接都会有所帮助。
谢谢你。
注意:抱歉,没有发布代码 sn-p,因为我处于初始阶段并卡在此过程中,所以我没有代码可显示。
【问题讨论】:
标签: android android-fragments phone-call
我想在通话过程中检查拨号盘是否被激活。我正在构思一个简单的应用程序,它需要在通话过程中知道拨号盘的状态。
任何代码 sn-p 或指向 tuts 的链接都会有所帮助。
谢谢你。
注意:抱歉,没有发布代码 sn-p,因为我处于初始阶段并卡在此过程中,所以我没有代码可显示。
【问题讨论】:
标签: android android-fragments phone-call
您可以通过使用 Java 反射获取内部 com.android.internal.telephony.ITelephony 对象来做到这一点。并使用showCallScreen(); 或showCallScreenWithDialpad
/**
* If there is currently a call in progress, show the call screen.
* The DTMF dialpad may or may not be visible initially, depending on
* whether it was up when the user last exited the InCallScreen.
*
* @return true if the call screen was shown.
*/
boolean showCallScreen();
/**
* Variation of showCallScreen() that also specifies whether the
* DTMF dialpad should be initially visible when the InCallScreen
* comes up.
*
* @param showDialpad if true, make the dialpad visible initially,
* otherwise hide the dialpad initially.
* @return true if the call screen was shown.
*
* @see showCallScreen
*/
boolean showCallScreenWithDialpad(boolean showDialpad);
用上述方法创建包名com.android.internal.telephony.ITelephony并放入ITelephony.aidl文件。当您编译相同的方法时,将在 gen 目录下创建具有相同包名的方法。然后你就可以像这样使用这个方法了。
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService;
telephonyService = (ITelephony)m.invoke(tm);
// Silence the ringer and answer the call!
telephonyService.showCalScreen();
但这可能不适用于Android 2.2+以上,我没有尝试过,但如果它有效,你可以尝试。在 Android 2.2+ 上,它有时会给出安全异常。下面是那个链接。
Neither user 10056 nor current process has android.permission.MODIFY_PHONE_STATE
【讨论】: