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 7701845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:05:28+00:00 2026-05-31T23:05:28+00:00

I would like to implement an application for block a mobile number for receiving

  • 0

I would like to implement an application for block a mobile number for receiving or sending calls and messages. In my application I am entering mobile number at EditText box then I am clicking a button for block the mobile number which has entered by the user.

I have implemented an activity class as follows:

public class BlockNumberActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ((Button)findViewById(R.id.block)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String mobileNumer = ((EditText)findViewById(R.id.mobileNum)).getText().toString();
                //How to block entered mobileNumber
            }
        });

        ((Button)findViewById(R.id.unblock)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String mobileNumer = ((EditText)findViewById(R.id.mobileNum)).getText().toString();
                //How to unblock entered mobileNumber
            }
        });
    }
}

I think we may use BroadcastReceiver. But I don’t have more knowledge on it. Please give me an idea how to implement blocking or unblocking mobile number.
Please any body help me…..

  • 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-05-31T23:05:29+00:00Added an answer on May 31, 2026 at 11:05 pm

    create PhoneCallReceiver .java

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.telephony.PhoneStateListener;
    import android.telephony.TelephonyManager;
    import android.util.Log;
    import android.widget.Toast;
    public class PhoneCallReceiver extends BroadcastReceiver {  
    
    @Override
    public void onReceive(Context context, Intent intent) { 
        TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        PhoneCallStateListener customPhoneListener = new PhoneCallStateListener(context);
        telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
    
    
    
    }}
    

    now create PhoneCallStateListener .java

    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);
    }}
    

    Now in src create this package com.android.internal.telephony now in this package Right Click -> New -> File now give name ITelephony.aidl and paste this code

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

    NOTE: Code is tested in Android 2.2 (Froyo),2.3 (GingerBread)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to implement asynchronous email sending in my web application when users
I'm building a mobile application using jQuery Mobile and I would like to implement
I would like to implement a command line interface for a Java application. This
I am creating an application and I would like to implement a progress window
I am developing an application for video capture and I would like to implement
I would like to implement multi-touch in my applications for Windows Mobile. The applications
In our ASP.NET 3.5 application, we would like to implement a "Please wait.." feature
I would like to implement Jquery EasyUI (http://www.jeasyui.com) in my asp.net application. If you
I would like to implement a check in my application to tell the user
I would like to implement a java application (server application) that can download a

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.