Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

android - Auto answer the incoming call programmatically?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As from here

Check this source

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...