Android:如何自动接听电话?

时间:2012-02-06 05:06:54

标签: 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");

但它也不起作用。 我错过了什么?

1 个答案:

答案 0 :(得分:-1)

更改以下内容

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

context.sendBroadcast(buttonDown);.

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