如何从我们的应用程序拨打来电

时间:2013-10-22 12:59:24

标签: android android-intent broadcastreceiver android-permissions

我正试图通过我提供的号码进行来电。总之,我想做假来电。因为我是新人所以我不理解如何完成这项任务。 我已经创建了incomingCallReceiver类,我正在收听电话的状态。

在我的活动类中,我正在调用incomingCallReceiver类。

这是我的 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 个答案:

答案 0 :(得分:1)

  

我想打假来电

您可以模拟通话应用屏幕。

答案 1 :(得分:1)

根据以下答案,不可能: