繁体   English   中英

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

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

我想在Android手机中禁用传入和传出呼叫的功能。我的Android手机应该只允许运行GPRS和其他应用程序。

我的Android机型是三星Ace

请建议我解决这个问题。 提前致谢。

此代码将阻止您的所有通话(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();
        }
    }
}

这里CALL_STATE_OFFHOOK状态将在您的呼叫连接和接到来电时每次呼叫

没有任何方法可以你知道天气是来电还是来电

但是你可以在两个场景中结束呼叫

任何你使用谷歌的Android API delevop ..

将位于Android的architcture的Applications层。 但是,管理调用是在Applications Framework层中实现的。 所以:

  • 如果要阻止来自应用程序的呼叫,则无法避免电话呼叫状态发生,因此一旦电话管理器处理了呼叫,请使用telephonyService.endCall()结束呼叫。

  • 如果你真的需要调用不要到达你的应用层..我认为需要一个自定义的android编译

  • 但您是否认为某些移动电话提供商提供阻止语音通道的“数据卡”? 这些是3G移动互联网调制解调器中的卡片

暂无
暂无

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

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