小编pra*_*k31的帖子

在Marshmallow上的Whatsapp/Viber/Line/Skype等VOIP应用程序的锁定屏幕上的来电

我们计划发布基于Twilio Voice SDK的Android应用程序更新.我们的客户想要更原生的体验,他们可以直接看到接受或拒绝电话的屏幕(就像Skype/Whatsapp/Viber/Line等),而不是点击通知然后再点击对话框.此外,这也应该在锁定屏幕上工作.

截至目前,我已成功在我的应用程序中打开一个活动并显示接受或拒绝按钮.它适用于应用程序处于前台或后台时.这是实现这一目标的代码片段.我修改了VoiceFirebaseMessagingService.java中的notify()方法,以便在每次调用onMessageRecived来显示来电通知时显示活动.

private void notify(CallInvite callInvite, int notificationId) {
        String callSid = callInvite.getCallSid();

        if (callInvite.getState() == CallInvite.State.PENDING) {
            soundPoolManager.playRinging();

            System.out.println("Disabling keyguard and accquiring wake lock");



            Intent intent = new Intent(this, OnCallActivityNew.class);
            intent.setAction(OnCallActivityNew.ACTION_INCOMING_CALL);
            intent.putExtra(OnCallActivityNew.INCOMING_CALL_NOTIFICATION_ID, notificationId);
            intent.putExtra(OnCallActivityNew.INCOMING_CALL_INVITE, callInvite);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent =
                    PendingIntent.getActivity(this, notificationId, intent, PendingIntent.FLAG_ONE_SHOT);
            /*
             * Pass the notification id and call sid to use as an identifier to cancel the
             * notification later
             */
            Bundle extras = new Bundle();
            extras.putInt(NOTIFICATION_ID_KEY, notificationId);
            extras.putString(CALL_SID_KEY, callSid);

            NotificationCompat.Builder notificationBuilder = …
Run Code Online (Sandbox Code Playgroud)

android voip twilio

6
推荐指数
1
解决办法
1636
查看次数

标签 统计

android ×1

twilio ×1

voip ×1