How to block calls in Android/Reject incoming calls in android/program to block unwanted calls in Android/Android call blocking example/blacklist example in android
Create an interface ITelephony.java with package name com.android.internal.telephony
ITelephony.java
package com.android.internal.telephony; public interface ITelephony { boolean endCall(); void answerRingingCall(); } |
Create a broadcast receiver and get incoming number from intent.
CallReceiver.java
package com.example; 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.os.Bundle; import android.telephony.TelephonyManager; public class CallReceiver extends BroadcastReceiver{ private String incomingnumber; @Override public void onReceive(Context context, Intent intent) { String s[]={"9000000000","800000000"}; Bundle b = intent.getExtras(); incomingnumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); try { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm); for (int i = 0; i < s.length; i++) { if(s[i].equals(incomingnumber)){ telephonyService.endCall(); } } } catch (Exception e) { // TODO: handle exception } } } |
In manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <receiver android:name=".CallReceiver"> <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> </intent-filter> </receiver> </application> </manifest> |
See more
Not a block incomming call of this code.. Please help
ReplyDeletee to evu j hoy bhura..
DeleteTry to add
ReplyDeleteto your manifest file
Try to add 'android.permission.CALL_PHONE' to your manifest file
DeleteThis comment has been removed by the author.
ReplyDeletehey it is working in my emulator but not in my phone.
Deletei have came to know that it is not supported nowadays. as they don't want third party apps to reject calls. it was working well in the past but not from now.