How to Block outgoing calls and Text SMS

后端 未结 4 1423
一个人的身影
一个人的身影 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:16

    To add the answer by Dharmendra saying that:

    There is no any method that you can know whether it is incoming call or outgoing call

    In fact, there is.

    To distinguish incoming calls from outgoing calls, you have to listen to Intent.ACTION_NEW_OUTGOING_CALL as well. Now:

    when you see first Intent.ACTION_NEW_OUTGOING_CALL and then CALL_STATE_OFFHOOK, it's an outgoing call;

    when you first see CALL_STATE_RINGING and then CALL_STATE_OFFHOOK, it's an incoming call.

    At second, you could either use a PhoneStateListener or listen to TelephonyManager.ACTION_PHONE_STATE_CHANGED. From what I could see, first the intent gets received by the BroadcastReceiver, then the PhoneStateListener gets notified.

    final IntentFilter theFilter = new IntentFilter();
    theFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    theFilter.addAction(Intent.ACTION_NEW_OUTGOING_CALL);
    mBroadcastReceiver = new MyBroadcastReceiver();
    mService.registerReceiver(mBroadcastReceiver, theFilter);
    
    class MyBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            ...
        }
    }
    

提交回复
热议问题