This question already has an answer here:
i am trying to make an incoming call from a number given by me. in short i want to make fake incoming call. as i am new so i am not understanding how to complete this task. i have created incomingCallReceiver class where i am listening state of phone call.
inside my activity class i am calling incomingCallReceiver class.
this is my IncommingCallReceiver
public class IncommingCallReceiver extends BroadcastReceiver
{
Intent mintent;
Context mcontext;
Bundle bundle;
public static String name1, phoneNumber1;
@Override
public void onReceive(Context context, Intent intent)
{
mintent = intent;
mcontext = context;
bundle = mintent.getExtras();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CALL_STATE;
bundle = intent.getExtras();
if(bundle !=null)
{
tm.listen(phoneStateListener, events);
}
}
private final PhoneStateListener phoneStateListener = new PhoneStateListener()
{
@Override
public void onCallStateChanged(int state, String incomingNumber)
{
String callState = "UNKNOWN";
state = bundle.getInt(TelephonyManager.EXTRA_STATE);
phoneNumber1 = bundle.getString("phonenumber");
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
Log.i("IncomingCallReceiver", "Incomng Number: " + phoneNumber1);
Toast.makeText(mcontext, "incomming call is idle", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
Log.i("IncomingCallReceiver", "Incomng Number: " + phoneNumber1);
Toast.makeText(mcontext, "incomming call is ringing", Toast.LENGTH_LONG).show();
Intent answer = new Intent(Intent.ACTION_MEDIA_BUTTON);
answer.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
mcontext.sendOrderedBroadcast(answer, "android.permission.CALL_PRIVILEGED");
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.i("IncomingCallReceiver", "Incomng Number: " + phoneNumber1);
Toast.makeText(mcontext, "incomming call is offhook", Toast.LENGTH_LONG).show();
break;
}
Log.i(">>>Broadcast", "onCallStateChanged " + callState);
super.onCallStateChanged(state, incomingNumber);
}
};
}
According to the following answer its impossible:
You can simulate phone call app screen.