My requirement is to, end all incoming calls. I have googled it and gone through these link1 and link2.
My issue is ::
From help from above links i tried to block call,it is though ending incoming calls,but after one single vibration. I dont want that single vibration, just want to cancel call directly without any kind of vibration or notification.
Here is my code ::
Manifest ::
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_INCOMING_CALLS" />
<receiver android:name=".PhoneStateBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
The receiver ::
public class PhoneStateBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.PHONE_STATE".equals(str)) {
Bundle localBundle = intent.getExtras();
String callState = localBundle.getString("state");
if (callState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
try{
TelephonyManager localTelephonyManager = (TelephonyManager) context.getSystemService("phone");
Method localMethod = Class.forName(localTelephonyManager.getClass()
.getName()).getDeclaredMethod("getITelephony", new Class[0]);
localMethod.setAccessible(true);
boolean bool = ((ITelephony)localMethod.invoke(localTelephonyManager,
new Object[0])).endCall();
return;
}catch (Exception localException){
localException.printStackTrace();
}
}
}
}
}
Create this Interface "ITelephony.java" under package "com.android.internal.telephony"
The ITelephony interface :
public abstract interface ITelephony extends IInterface{
public abstract void answerRingingCall() throws RemoteException;
public abstract boolean endCall() throws RemoteException;
public abstract void silenceRinger() throws RemoteException;
public static abstract class Stub extends Binder implements ITelephony{
private static final String DESCRIPTOR = "com.android.internal.telephony.ITelephony";
static final int TRANSACTION_answerRingingCall = 2;
static final int TRANSACTION_endCall = 1;
static final int TRANSACTION_silenceRinger = 3;
public Stub(){
attachInterface(this, "com.android.internal.telephony.ITelephony");
}
public static ITelephony asInterface(IBinder paramIBinder){
if (paramIBinder == null)
return null;
IInterface localIInterface = paramIBinder.
queryLocalInterface("com.android.internal.telephony.ITelephony");
if ((localIInterface != null) && ((localIInterface instanceof ITelephony)))
return (ITelephony)localIInterface;
return new Proxy(paramIBinder);
}
public IBinder asBinder(){
return this;
}
public boolean onTransact(int paramInt1, Parcel paramParcel1,
Parcel paramParcel2, int paramInt2)throws RemoteException {
switch (paramInt1){
default:
return super.onTransact(paramInt1, paramParcel1, paramParcel2, paramInt2);
case 1598968902:
paramParcel2.writeString("com.android.internal.telephony.ITelephony");
return true;
case 1:
paramParcel1.enforceInterface("com.android.internal.telephony.ITelephony");
boolean bool = endCall();
paramParcel2.writeNoException();
if (bool);
for (int i = 1; ; i = 0)
{
paramParcel2.writeInt(i);
return true;
}
case 2:
paramParcel1.enforceInterface("com.android.internal.telephony.ITelephony");
answerRingingCall();
paramParcel2.writeNoException();
return true;
case 3:
}