Reputation: 1177
i have incoming call broadcast receiver and phone state listener class , how to block or reject incoming call and the ringing notification
BroadCastReceiver
public class PhoneCallReceiver extends BroadcastReceiver{
private static final String TAG = "Phone call";
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Receving....");
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
SamplePhoneStateListener customPhoneListener = new SamplePhoneStateListener();
telephony.listen(customPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
Phone Listener
public class SamplePhoneStateListener extends PhoneStateListener {
private static final String TAG = "Phone Listner";
@Override
public void onCallStateChanged(int state, String incomingNumber) {
Log.v(TAG, "Current State is - "+state);
Log.v(TAG, incomingNumber);
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
Log.d(TAG, "Phone Ringigg");
break;
}
super.onCallStateChanged(state, incomingNumber);
}
}
Upvotes: 0
Views: 3328
Reputation: 1
To block a call u have to use java reflections and access hidden file of android.telephony
package. this file (ITelephony.java
) has a function called endcall()
which uses permissions. this is not advised by google team as recieving and ending calls in a programmatic way is invasion of user privacy.
Upvotes: 0
Reputation: 17051
make sure you have the permission android.permission.READ_PHONE_STATE set up.
Upvotes: 1