Android:如何自动接听电话?

标签 android hook action call headset

我试图让我的手机自动接听电话,但谷歌似乎删除了这种方式的权限:

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);
telephonyService.silenceRinger();
telephonyService.answerRingingCall();

所以我在这里找到其他方法: http://code.google.com/p/auto-answer/source/browse/trunk/src/com/everysoft/autoanswer/AutoAnswerIntentService.java

// 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");

但是也行不通。 我想念什么?

最佳答案

更改以下内容

context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

context.sendBroadcast(buttonDown);.

与 buttonUp 相同。因为 sendOrderedBroadcast() 可以被其他接收者中止。

关于Android:如何自动接听电话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155794/

相关文章:

jquery - ASP.NET MVC - 通过 jQuery 调用操作

java - 添加 xml 验证文件后没有为操作定义结果

android - 从 Gradle 上的辅助模块获取资源

node.js - Sequelize查询执行顺序错误

android - Android 渲染脚本可以在 GPU 上运行吗?

linux - 如何使用 JNA 在 Linux (X11 lib) 上 Hook 鼠标?

php - 从 GIT post-update hook 执行 PHP

c# - 如何将一个函数及其对象引用传递给另一个要执行的函数

java - "W/AudioFlinger( 34): write blocked for 70 msecs, 2236 delayed writes, thread "是什么意思?

android - Activity 不启动