How to disconnect incoming call in android by programatically

走远了吗. 提交于 2020-01-01 06:26:22

问题


I want to disconnect incoming call for a particular time.

How can i do this is it impossible ?

I searched and i find it is impossible. please help me.

public class Telephony3 extends Service 
{
  Context context;  
    public IBinder onBind(Intent intent) 
    {

        return null;
    }

    public void onCreate() 
    {
        super.onCreate();
        try
        {
            StateListener phoneStateListener = new StateListener();
            TelephonyManager telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
            telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);  
        }catch(Exception e)
            {
                e.printStackTrace();
            }

    }  

    class StateListener extends PhoneStateListener{
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);
            switch(state){
                case TelephonyManager.CALL_STATE_RINGING:
                    //Disconnect the call here...
                    try{
                        TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
                        Class c = Class.forName(manager.getClass().getName());
                        Method m = c.getDeclaredMethod("getITelephony");
                        m.setAccessible(true);
                        ITelephony telephony = (ITelephony)m.invoke(manager);
                        telephony.endCall();
                    }catch(Exception e){
                        Log.d("",e.getMessage());
             }

                    break;
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    break;
                case TelephonyManager.CALL_STATE_IDLE:
                    break;
            }
        }
    };
    public void onDestroy()
    {

    }

}

///////////////////////////////////////////
make another package com.android.internal.telephony and make one interface ITelephony

public interface ITelephony 
{
    boolean endCall();

    void answerRingingCall();

    void silenceRinger();

}

and when i call this emulator from another the calling is happening. any thing wrong here please suggest me.

thanks in advance


回答1:


You can generate your own activity that handles action "ACTION_ANSWER".

Register your application component as a intent handler.




回答2:


Here is a blog post which suggest a possible workaround.




回答3:


Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);             
  buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
  getContext().sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");

from

http://androidbridge.blogspot.com/2011/05/how-to-answer-incoming-call-in-android.html



来源:https://stackoverflow.com/questions/9059818/how-to-disconnect-incoming-call-in-android-by-programatically

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