Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:20:53+00:00 2026-06-17T09:20:53+00:00

I am trying to block incoming call for a particular number. first I try

  • 0

I am trying to block incoming call for a particular number. first I try for all incoming call.
it works well.
but when I try for a particular number by the following code the call is not rejected and the phone is ringing ,I tried with my android phone..

       @Override
     public void onReceive(Context context, Intent intent) {
      Log.v(TAG, "Receving....");
      String t1="01741297163",t2="08801741297163";
      TelephonyManager telephony = (TelephonyManager) 
      context.getSystemService(Context.TELEPHONY_SERVICE);  
      try {
       Class c = Class.forName(telephony.getClass().getName());
       Method m = c.getDeclaredMethod("getITelephony");
       m.setAccessible(true);
       Bundle b=intent.getExtras();
       num=b.getString(telephony.EXTRA_INCOMING_NUMBER);
       if(num.equals(t1)||num.equals(t2)){
       telephonyService = (ITelephony) m.invoke(telephony);
       //telephonyService.silenceRinger();
       telephonyService.endCall();
      } }catch (Exception e) {
       e.printStackTrace();
      }

I do not know the format of incoming number get from the Telephonymanager.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:20:54+00:00Added an answer on June 17, 2026 at 9:20 am
    import java.lang.reflect.Method;
    
    import android.content.Context;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.media.AudioManager;
    import android.os.Bundle;
    import android.preference.PreferenceManager;
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.widget.Toast;
    
    import com.android.internal.telephony.ITelephony;
    
    public class PhoneCallStateListener extends PhoneStateListener {    
    
    private Context context;
    public PhoneCallStateListener(Context context){
        this.context = context;
    }
    
    
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {  
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(context);
    
    switch (state) {
    
        case TelephonyManager.CALL_STATE_RINGING:       
    
          String block_number = prefs.getString("block_number", null);
                AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 
                //Turn ON the mute
        audioManager.setStreamMute(AudioManager.STREAM_RING, true);                 
                TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        try {
        Toast.makeText(context, "in"+block_number, Toast.LENGTH_LONG).show();
        Class clazz = Class.forName(telephonyManager.getClass().getName());
        Method method = clazz.getDeclaredMethod("getITelephony");
        method.setAccessible(true);
        ITelephony telephonyService = (ITelephony) method.invoke(telephonyManager);     
        //Checking incoming call number
        System.out.println("Call "+block_number);
        if (incomingNumber.equalsIgnoreCase("+91"+block_number)) {
        //telephonyService.silenceRinger();//Security exception problem
         telephonyService = (ITelephony) method.invoke(telephonyManager);
         telephonyService.silenceRinger();
        System.out.println(" in  "+block_number);
        telephonyService.endCall();
        }
        } catch (Exception e) {
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
        }
            //Turn OFF the mute     
        audioManager.setStreamMute(AudioManager.STREAM_RING, false);
        break;
        case PhoneStateListener.LISTEN_CALL_STATE:
        }
        super.onCallStateChanged(state, incomingNumber);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to block all email providers except some of theme, PHP code :
I am trying to create an app that can block an incoming call. I
I'm trying to add {{block type=core/template template=page/home.phtml}} Into a CMS page but it's not
I'm trying to do repeat a code block, but have something happen every 5th
I'm trying to block viewing a javascript page (.js) if user is not logged
I am trying to block all default methods except create and update in my
In my block code I am trying to programmatically retrieve a list of products
I am trying to code AES using Cipher Block Chaining(CBC) mode. I am pretty
I am trying to block the website to be viewed as not exist from
I'm trying to block all non-localhost attempts to access a Webrick process. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.