Android Twilio视频通话,唤醒应用程序并进入前台 [英] Android Twilio Video Call, wake up app and bring to foreground

查看:255
本文介绍了Android Twilio视频通话,唤醒应用程序并进入前台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Twilio视频通话提供本地视频通话体验。情况如下:

I am trying to provide a native video calling experience with Twilio Video Call. Here is the scenario:


  1. 人员AAA呼叫人员BBB。

  2. 人员BBB没有应用处于打开状态,无论是在后台还是在前台,应用都处于终止状态,甚至可能锁定了电话。

  3. 当AAA呼叫到达时,该应用会打开并显示带有答案的视频ui按钮。就像在WhatsApp中一样,Google Duo,Skype ...

我们已经建立了FCM,并且正在接收推送通知。尝试在通话到达时立即打开视频通话接听按钮,而不单击通知,就像在Whatsapp,Google Duo中一样(在Android手机中)

We have FCM in place and are receiving a push notification. Trying to open the video call answer button the moment the call arrives, without clicking the notification, just like in Whatsapp, Google Duo... (in Android phones)

尝试在后台打开套接字的情况下运行服务。当向套接字发出传入的呼叫事件时,套接字将监听传入的呼叫并打开VideoCallActivity。

We tried to have a Service running in the background with a socket open in it. The socket would listen to incoming calls and open the VideoCallActivity when an incoming call event is emitted to the socket.

这是我们最好的选择,但到目前为止没有成功。您将如何实现此功能?

This was our best bet but no success so far. How would you achieve this functionality?

推荐答案

所以我们已经找到了解决方案(当收到通知时,将应用程序置于前台),即使有一段时间了,我仍在发布它:

So we had figured out this solution (when a notification arrives, bring the app to foreground) and I'm posting it even though it's been a while:


  1. FCM通知(firebase云消息传递通知)需要仅在通知中发送数据。因此,通知的JSON结构中没有Notification对象,只有数据。这样,您的应用的FirebaseMessagingService.java类将处理通知。请详细阅读以下内容,以了解如何处理两种FCM通知类型。
    https://firebase.google.com/docs/cloud-messaging / android / receive
    https:// firebase .google.com / docs / cloud-messaging / concept-options#notifications_and_data_messages

在FirebaseMessagingService.java类中,使用以下命令启动VideoCall活动一个意图。不要忘记将此服务添加到Manifest.xml

In the FirebaseMessagingService.java class, launch a VideoCall activity with an Intent. Don't forget to add this service to the Manifest.xml

        Intent intent = new Intent(this, VideoCallActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        getApplicationContext().startActivity(intent);


  • 在VideoCall活动中,请确保您在onCreate( ):

  • In the VideoCall activity, make sure you have the below code in the beginning of onCreate() :

    // These flags ensure that the activity can be launched when the screen is locked.
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    
    // to wake up screen
    PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
    wakeLock.acquire();
    
    // to release screen lock
    KeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE);
    KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();
    


  • 使用适当的意图过滤器将VideoCallActivity添加到Manifest.xml中:

  • Add the VideoCallActivity to the Manifest.xml with the appropriate intent-filter:

    < ;!-视频通话->
    < activity
    android:name =。ui.activities.video_call.VideoCallActivity
    android:launchMode = singleTop
    android:screenOrientation = portrait
    android:theme = @ style / AppTheme.NoActionBar>
    < intent-filter>
    < ;!-注意:这些动作是通知动作->
    < action android:name = VIDEO_CALLING />
    < category android:name = android.intent.category.DEFAULT />
    < / intent-filter>
    < / activity>

    可选:
    至使电话响起并震动:

    Optional: To make the phone ring and vibrate:

    // For Incoming Call
    // 1. declare
    private MediaPlayer incomingCallMediaPlayer;
    // .2 in onCreate, if I'm the person that's calling, ring the phone 
    incomingCallMediaPlayer = MediaPlayer.create(this, R.raw.incoming);
    incomingCallMediaPlayer.setLooping(true);
    incomingCallMediaPlayer.start();
    // 3. when I pick up, stop the player
    incomingCallMediaPlayer.stop();
    
    // I play R.raw.incoming if I'm being called.
    // I play R.raw.outgoing when I'm calling.
    // I understand if I'm the one calling from the number of participants in the "room" (this is a video call terminology) and by passing in a variable through the intent
    
    // For Outgoing Call
    // 1. declare
    private MediaPlayer callingMediaPlayer;
    // 2. in onCreate, if I'm being called, ring the phone
    callingMediaPlayer = MediaPlayer.create(this, R.raw.outgoing);
    callingMediaPlayer.setLooping(true);
    callingMediaPlayer.start();
    // 3. when another "participant" (this is a video call terminology) joins the "room" I stop playing the sound
    callingMediaPlayer.stop();
    
    // to Vibrate, add the code with the media players and stop vibrate with media players
    //https://stackoverflow.com/questions/13950338/how-to-make-an-android-device-vibrate
    

    这篇关于Android Twilio视频通话,唤醒应用程序并进入前台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆