以编程方式自动接听来电?

时间:2012-01-05 09:33:16

标签: android phone-call incoming-call

我有获取Android手机来电号码的代码。但是,当来电来自特定号码时,我想自动接听来电。

我在网上找到了这段代码:

public class ServiceReceiver extends BroadcastReceiver {
    private static final String TAG = null;

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
        MyPhoneStateListener phoneListener = new MyPhoneStateListener();
        TelephonyManager telephony = (TelephonyManager)
                context.getSystemService(Context.TELEPHONY_SERVICE);
        telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
        Bundle bundle = intent.getExtras();
        String phoneNr = bundle.getString("incoming_number");
        Log.v(TAG, "phoneNr: " + phoneNr);
        String numb = "+4348873541";

        Class c = Class.forName(telephony.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        if (phoneNr.equals(numb)) {
            ITelephony telephonyService = (ITelephony) m.invoke(telephony);
            telephonyService = (ITelephony) m.invoke(telephony);
            telephonyService.silenceRinger();
            telephonyService.answerRingingCall();
        }
    }
}

您能告诉我如何从特定号码自动接听电话吗?

1 个答案:

答案 0 :(得分:7)

here

开始

选中此source

  

他们发送蓝牙“keydown”事件来接听电话!