简体   繁体   English

如何在Android手机中禁用传入和传出呼叫

[英]How to disable incoming & outgoing calls in android phone

I want to disable the feature of incoming and outgoing calls in the Android phone.My android phone should only allow GPRS & other applications to be run. 我想在Android手机中禁用传入和传出呼叫的功能。我的Android手机应该只允许运行GPRS和其他应用程序。

My Android model is Samsung Ace 我的Android机型是三星Ace

Please suggest me solution regarding this. 请建议我解决这个问题。 Thanks in Advance. 提前致谢。

This code will block your all call (INCOMING AND OUTGOING) 此代码将阻止您的所有通话(INCOMING AND OUTGOING)

import java.lang.reflect.Method;

import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

import com.CallLogApp.helper.BlockNumberHelper;
import com.CallLogApp.util.UDF;
import com.android.internal.telephony.ITelephony;

public class CustomPhoneStateListener extends PhoneStateListener {

    //private static final String TAG = "PhoneStateChanged";
    Context context;
    public CustomPhoneStateListener(Context context) {
        super();
        this.context = context;
    }

    @Override
    public void onCallStateChanged(int state, String outGoingNumber) {
        super.onCallStateChanged(state, outGoingNumber);

        switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                endCallIfBlocked(outGoingNumber);
                break;
            case TelephonyManager.CALL_STATE_RINGING:
                break;
            default:
                break;
        }

     }

     private void endCallIfBlocked(String outGoingNumber) {
        try {
            // Java reflection to gain access to TelephonyManager's
            // ITelephony getter
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            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);  

            if (new BlockNumberHelper(context).isBlocked(outGoingNumber))
            {
                telephonyService = (ITelephony) m.invoke(tm);
                telephonyService.silenceRinger();
                telephonyService.endCall();
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Here CALL_STATE_OFFHOOK state will call each time when your call going to connect and when you received incoming call 这里CALL_STATE_OFFHOOK状态将在您的呼叫连接和接到来电时每次呼叫

There is no any method that you can know weather it is incoming call or outgoing call 没有任何方法可以你知道天气是来电还是来电

But you can end call which is going to connect in both scenario 但是你可以在两个场景中结束呼叫

Anything you delevop using google's android API.. 任何你使用谷歌的Android API delevop ..

Would be located in the Applications layer of Android's architcture . 将位于Android的architcture的Applications层。 But managing calls is something implemented in the Applications Framework layer. 但是,管理调用是在Applications Framework层中实现的。 So: 所以:

  • If you want to block calls from an application you can't avoid the phone call state to happen, so once the telephony manager has handled the call, end it with telephonyService.endCall(). 如果要阻止来自应用程序的呼叫,则无法避免电话呼叫状态发生,因此一旦电话管理器处理了呼叫,请使用telephonyService.endCall()结束呼叫。

  • If you really need calls not to reach your application layer.. I think a custom android compilation would be needed 如果你真的需要调用不要到达你的应用层..我认为需要一个自定义的android编译

  • But have you considered that some mobile telephony providers offer "data cards" for which they block voice channels? 但您是否认为某些移动电话提供商提供阻止语音通道的“数据卡”? These are the kind of cards that come in 3G mobile internet modems 这些是3G移动互联网调制解调器中的卡片

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

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