简体   繁体   English

启动后如何停止intent.ACTION_CALL?

[英]How to stop a intent.ACTION_CALL once started?

I am using Intent intent = new Intent(Intent.ACTION_CALL); 我正在使用Intent intent = new Intent(Intent.ACTION_CALL); to make a call from my application. 从我的应用程序拨打电话。

is there any way to terminate the call after a period of time? 一段时间后有什么办法可以终止通话? Or set a timer for ACTION_CALL before it starts? 还是在ACTION_CALL开始之前设置一个计时器?

I am using the below code from Prasanta's Blog, but for some reason context is getting the error below. 我正在使用Prasanta博客中的以下代码,但是由于某种原因, context在下面出现了错误。 Any suggestions? 有什么建议么?

cannot be resolved 无法解决

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

}
    }
}

Your question has been asked a number of times. 您的问题已被问过很多次。 The short answer is that there is no official way to do that. 简短的答案是,没有官方的方法可以做到这一点。

The long answers: 长答案:

Read them carefully. 仔细阅读它们。 Look for the cases where someone says "used to work...". 查找有人说“曾经工作过……”的情况。

In one of the questions someone proposed to turn on airplane mode (the app need permissions to do that, of course). 在一个问题中,有人建议打开飞行模式(应用程序当然需要权限才能执行此操作)。 It's crude, but it works. 这很粗糙,但是行得通。 As a user, I would have some reservations about an app doing that, though. 但是,作为用户,我会对这样做的应用程序有所保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM