1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.widget.Toast;
import android.view.KeyEvent;
public class AutoReceiverIncomingCall extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String extraState =intent.getStringExtra(TelephonyManager.EXTRA_STATE); //Getting Extra State
if (extraState.equals(TelephonyManager.EXTRA_STATE_RINGING)) //Checking Phone State (Ringing or Not)
{
//If the Phone is Ringing getting the Incoming number/
String incomingNumber =intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (incomingNumber.contentEquals("+33"))
{
//---answer the call---
// Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);
//buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
//Context().sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
//
Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON);
i.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK));
context.sendOrderedBroadcast(i, "android.permission.CALL_PRIVILEGED");
// i = new Intent(Intent.ACTION_MEDIA_BUTTON);
// i.putExtra(Intent.EXTRA_KEY_EVENT,new KeyEvent(KeyEvent.ACTION_UP,KeyEvent.KEYCODE_HEADSETHOOK));
//context.sendOrderedBroadcast(i, null);
//sendKeys(KeyEvent.KEYCODE_ENDCALL);
//
//setResultData(null);
Toast.makeText(context, "NEW_OUTGOING_CALL intercepted to number 123-123-1234 - aborting call",
Toast.LENGTH_LONG).show();
}
}
return;
} |
Partager