Is there a way on Android to intercept incoming calls/SMSes to either block/unblock it?

前端 未结 3 782
醉梦人生
醉梦人生 2020-12-15 02:04

Is there a way to intercept incomming calls/SMSes (to block or unblock it) on the basis of mobile numbers which are added to screening list?

3条回答
  •  粉色の甜心
    2020-12-15 02:44

    ----> For your question, I think the following will be helpful.

    package android_programmers_guide.PhoneCallReceiver;
    import java.lang.reflect.Method;
    import com.android.internal.telephony.ITelephony;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.telephony.TelephonyManager;
    import android.util.Log;
    import android.widget.Toast;
    public class PhoneCallReceiver extends BroadcastReceiver
    {
        Context context = null;
        private static final String TAG = "THIRI THE WUT YEE";
        private ITelephony telephonyService;
        @Override
        public void onReceive(Context context, Intent intent) 
        {
            Log.v(TAG, "Receving....");
            TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);  
            try 
            {
                Class c = Class.forName(telephony.getClass().getName());
                Method m = c.getDeclaredMethod("getITelephony");
                m.setAccessible(true);
                telephonyService = (ITelephony) m.invoke(telephony);
    
                Toast tag = Toast.makeText(context, "Call is not allowed in the meeting!!!", Toast.LENGTH_LONG);
                tag.setDuration(25);
                tag.show();
    
    
                telephonyService.silenceRinger();
                telephonyService.endCall();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }
    
     }
    
    
    }
    

    -----> Here is interface class

    package com.android.internal.telephony;
    interface ITelephony 
    {
        boolean endCall();
        void answerRingingCall();
        void silenceRinger();
    }
    

    ----> And the Manifest is as follows

        
            
                
                    
                    
                
    
            
            
                
                    
                
            
    
    
        
        
        
        
        
    
     
    

    ---> Honestly, I've found this code on the internet Cheers!

提交回复
热议问题