How to Block outgoing calls and Text SMS

后端 未结 4 1411
一个人的身影
一个人的身影 2020-11-29 05:49

I am developing an App in which I need to block the teenager from using mobile while driving, I need to block the call and sms. please help . any small hints and clues will

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 06:10

    To block outgoing calls, you need to register a PhoneStateListener like:

    telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    telephonyManager.listen(new MyListener(), PhoneStateListener.LISTEN_CALL_STATE);
    

    Then define your MyListener class like:

    private class Test extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            super.onCallStateChanged(state, incomingNumber);
    
    
            switch(state)
            {
            case TelephonyManager.CALL_STATE_IDLE:
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK://this case is for outgoing call 
                break;
            case TelephonyManager.CALL_STATE_RINGING://this case is for incoming call
                break;
            default:
                break;
            }
    
        }
    }
    

提交回复
热议问题