如何在android中按下结束呼叫时终止任何应用程序?

发布于 2025-01-02 01:20:36 字数 535 浏览 0 评论 0原文

我正在“TelephonyManager.EXTRA_STATE_OFFHOOK” 上启动一项活动,效果也很好。但在“TelephonyManager.EXTRA_STATE_IDLE”中我想终止之前打开的活动。我尝试设置全局变量,并且该全局变量与我的活动交互,根据该变量的真实值,我尝试“finish()”该活动。但当 "TelephonyManager.EXTRA_STATE_IDLE" 完成后,我变得无助。你能帮我一下吗?

由于很多应用程序都使用END CALLHOME BUTTON,我们可以在实际应用程序中逻辑地实现这些吗?

我提到过

1) TelephonyManager.EXTRA_STATE_OFFHOOK
2) TelephonyManager.EXTRA_STATE_IDLE are in MyReceiver class which extends BroadcastReceiver.

I am starting an activity on"TelephonyManager.EXTRA_STATE_OFFHOOK" and it works well also. but in"TelephonyManager.EXTRA_STATE_IDLE" i want to terminate that previously opened activity. I tried setting global variable, and that global variable interact my activity, on that variable's true value i tried to "finish()" that activity. But as "TelephonyManager.EXTRA_STATE_IDLE" done, i become helpless. Can you please help me out?

As so many application usesEND CALL and HOME BUTTON, can we implement these by logically in real application?

I mentioned

1) TelephonyManager.EXTRA_STATE_OFFHOOK
2) TelephonyManager.EXTRA_STATE_IDLE are in MyReceiver class which extends BroadcastReceiver.

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

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

发布评论

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

评论(1

阪姬 2025-01-09 01:20:36

在遇到了上述问题这么多麻烦之后,我通过逻辑来解决这个问题!

您只需将此代码添加到您的活动中

 PhoneStateListener listener;

      // Get the telephony manager
      telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

      // Create a new PhoneStateListener
      listener = new PhoneStateListener() 
      {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

          switch (state) 
          {
            case TelephonyManager.CALL_STATE_IDLE:
                Log.i("MainScreen", "IDLE");                    
                finish(); // It will close current activity on pressing the END CALL Button!!
                break;

          }

        }
      };

      // Register the listener with the telephony manager
      telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);

After having so much trouble with above question, i come to solve this by logically!!

you just have to add this code into your activity

 PhoneStateListener listener;

      // Get the telephony manager
      telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

      // Create a new PhoneStateListener
      listener = new PhoneStateListener() 
      {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

          switch (state) 
          {
            case TelephonyManager.CALL_STATE_IDLE:
                Log.i("MainScreen", "IDLE");                    
                finish(); // It will close current activity on pressing the END CALL Button!!
                break;

          }

        }
      };

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