【问题标题】:How to stop a intent.ACTION_CALL once started?一旦开始,如何停止intent.ACTION_CALL?
【发布时间】:2026-01-26 22:25:02
【问题描述】:

我正在使用Intent intent = new Intent(Intent.ACTION_CALL); 从我的应用程序中拨打电话。

有什么方法可以在一段时间后终止通话?或者在 ACTION_CALL 开始之前设置一个计时器?

我正在使用来自 Prasanta 博客的以下代码,但由于某种原因 context 收到以下错误。有什么建议吗?

无法解决

import java.lang.reflect.Method;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.RemoteException;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.telephony.ITelephony;


public class AnswerActivity extends Activity {
    private static final String TAG = null;
    /** Called when the activity is first created. */
    private ITelephony telephonyService;
    TelephonyManager telephonyManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    TelephonyManager tm = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);{

    try {
        // Java reflection to gain access to TelephonyManager's
        // ITelephony getter
        Log.v(TAG, "Get getTeleService...");
        Class c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        com.android.internal.telephony.ITelephony telephonyService =
                (ITelephony) m.invoke(tm);
    } catch (Exception e) {
        e.printStackTrace();
        Log.e(TAG,
                "FATAL ERROR: could not connect to telephony subsystem");
        Log.e(TAG, "Exception object: " + e);
    }

}
    }
}

【问题讨论】:

  • 看到这个帖子*.com/questions/599443/…
  • @MoshErsan 谢谢,我已经阅读了那篇文章,但我无法实施。上下文无法解析错误
  • @MoshErsan 我更新了代码和错误。感谢您的帮助。

标签: java android android-intent phone-call


【解决方案1】:

您的问题已被多次询问。简短的回答是没有官方的方法可以做到这一点。

长答案:

仔细阅读它们。寻找有人说“曾经工作......”的情况。

在有人提议打开飞行模式的问题之一中(该应用当然需要权限才能做到这一点)。它很粗糙,但它有效。不过,作为用户,我会对应用这样做有所保留。

【讨论】:

  • 谢谢,我去看看。这不是面向市场的应用程序或类似的东西。用于我公司的网络测试。