在intent活动运行时完成它



我有一个ACTION_CALL意图活动,我想用代码停止。

问题存在于2.3.3,当我结束一个呼叫,它会进入呼叫记录,而不是直接返回到应用程序,在4.1+工作。

我发现你可以使用finishActivity(requestCode)来完成一个不工作在我的代码活动

下面是我的代码:
    startActivityForResult(callIntent, 2);

    // when I call finishActivity here it works fine and activity ends immediately
    // finishActivity(2);
    if (endCall) 
    {
        callEndTimer = new CountDownTimer(10000, 1000) //End call after 10 seconds
        {
            public void onTick(long millisUntilFinished)
            {
            }
            public void onFinish()
            {
                // end the call
                TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(
                        Context.TELEPHONY_SERVICE);
                Class<?> c;
                try
                {
                    c = Class.forName(tm.getClass().getName());
                    Method m = c.getDeclaredMethod("getITelephony");
                    m.setAccessible(true);
                    Object telephonyService = m.invoke(tm);
                    c = Class.forName(telephonyService.getClass().getName());
                    m = c.getDeclaredMethod("endCall");
                    m.setAccessible(true);
                    m.invoke(telephonyService);
                    // Call ends here so I know the code is working
                    // When I call finishActivity(2) here the activity doesn't end and continues to go to the call logs
                    finishActivity(2);
                } catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }.start();
    }

你知道为什么我不能结束这个活动吗?

如果您在类中扩展Activity,只需在您希望活动停止的地方调用finish()

最新更新