Auto answer the incoming call programmatically?

穿精又带淫゛_ 提交于 2019-11-26 21:39:11

问题


I have the code for getting the number of the incoming call to a android phone. But I want to automatically answer the call when the incoming call is from a particular number.

I found this code on the internet:

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();
        }
    }
}

Can you please tell me how to auto answer the call from a particular number?


回答1:


As from here

Check this source

They send a Bluetooth "keydown" event to answer the call!



来源:https://stackoverflow.com/questions/8740223/auto-answer-the-incoming-call-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!