how to make an incoming call from our application

2019-09-20 11:19发布

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);
        }
    };
}

2条回答
成全新的幸福
2楼-- · 2019-09-20 11:46

According to the following answer its impossible:

查看更多
姐就是有狂的资本
3楼-- · 2019-09-20 11:56

i want to make fake incoming call

You can simulate phone call app screen.

查看更多
登录 后发表回答