如何以编程方式断开Android中的来电

发布于 2024-12-29 20:58:38 字数 2214 浏览 2 评论 0原文

我想在特定时间断开来电。

我该怎么办,这是不可能的吗?

我搜索了一下,发现这是不可能的。请帮我。

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

}

当我从另一个模拟器调用这个模拟器时,调用正在发生。这里有什么问题请建议我。

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独难免 2025-01-05 20:58:38

您可以生成自己的活动来处理操作“ACTION_ANSWER”。

将您的应用程序组件注册为意图处理程序。

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

Register your application component as a intent handler.

仙女 2025-01-05 20:58:38

这里 是一篇博客文章,其中建议了一种可能的方法解决方法。

Here is a blog post which suggest a possible workaround.

空心空情空意 2025-01-05 20:58:38
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");

来自

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文