如何在来电时在锁定屏幕上显示自定义弹出窗口

时间:2016-12-29 14:53:23

标签: android android-layout twilio twilio-api twilio-click-to-call

我正在使用twilio拨打电话和接听电话。我通过在onResum()方法中使用intent来接收传入呼叫。如何通过在连接上使用intent来获取传入号码。此外,我希望在移动屏幕锁定时显示自定义弹出窗口。

This is my code for receiving call.



 @Override
    public void onResume() {
        super.onResume();

        Intent intent = getIntent();
        if (intent != null) {
            /*
             * Determine if the receiving Intent has an extra for the incoming connection. If so,
             * remove it from the Intent to prevent handling it again next time the Activity is resumed
             */
            Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
            Connection incomingConnection = intent.getParcelableExtra(Device.EXTRA_CONNECTION);
//            Intent broadcast = new Intent(this, PhoneStateReceiver.class);
//            NewVoiceCallFragment client = new NewVoiceCallFragment(incomingConnection);
//            Intent intent1 = new Intent(this, CallDetectService.class);

            String incoming_number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
            if (incomingConnection == null && device == null) {
                return;
            }
            intent.removeExtra(Device.EXTRA_DEVICE);
            intent.removeExtra(Device.EXTRA_CONNECTION);

            pendingConnection = incomingConnection;
            pendingConnection.setConnectionListener(this);
            mobjSessionManager.setKeyIncomingCollsid(pendingConnection.getParameters().get(incomingConnection.IncomingParameterCallSIDKey));

            String incomingRecipientCallSid = pendingConnection.getParameters().get(incomingConnection.IncomingParameterCallSIDKey);
            String incomingRecipientCallNumber = pendingConnection.getParameters().get(incomingConnection.IncomingParameterFromKey);

            if (incomingRecipientCallNumber.equals(mobjSessionManager.getKeyCallerid())) {
                tManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);

                if (isDisplayDilog) {
                    switch (getRingingMode())
                    {
                        case 1:
                            audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                            break;
                        case 2:
                            audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                            break;
                        case 3:
                            audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                            break;
                    }
//                    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
//                    AsyninvokeIncomingNumber ser=new AsyninvokeIncomingNumber();
//                    ser.execute();
//                    Device.State str=device.getState();

                    unlockScreen();
                    showIncomingDialog();
                }

            }

        }
    }



//for ring :

    private int getRingingMode()
    {
        AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

        switch (am.getRingerMode()) {
            case AudioManager.RINGER_MODE_SILENT:
                return 1;
//                break;
            case AudioManager.RINGER_MODE_VIBRATE:
                return 2;
//                break;
            case AudioManager.RINGER_MODE_NORMAL:
                return 3;
//                break;
        }
        return 0;
    }



  //  for unlock screen
    private void unlockScreen() {
        Window window = this.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
        window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);



    }    

0 个答案:

没有答案