android 4.0.3 来电自动应答

2024-03-21

我过去一年从事 Android 技术工作。目前我想在 Android 4.0.3 中开发一个应用程序来电自动应答,但在这个版本中我没有得到任何解决方案或找不到任何 api (ITelephony.aidl)。请建议我。


它的工作代码。 首先找出其来电使用Phone状态的Broadcast Receiver。

    filter.addAction("android.intent.action.PHONE_STATE");
    mContext.registerReceiver(myCallReceiver, filter);

然后在onReceive(Context context, Intentintent)中调用answerPhoneHeadsethook()函数。

private void answerPhoneHeadsethook(Context context) {
    // Simulate a press of the headset button to pick up the call
    Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(
            KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(buttonDown,
            "android.permission.CALL_PRIVILEGED");

    // froyo and beyond trigger on buttonUp instead of buttonDown
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(
            KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
    context.sendOrderedBroadcast(buttonUp,
            "android.permission.CALL_PRIVILEGED");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

android 4.0.3 来电自动应答 的相关文章

随机推荐