Android Twilio视频通话,唤醒应用程序并进入前台

Android Twilio视频通话,唤醒应用程序并进入前台,第1张

概述我正在尝试通过Twilio视频通话提供本地视频通话体验.这是场景:>人AAA呼叫人BBB.>人员BBB没有打开应用程序,在后台或前景中,应用程序处于杀死状态,甚至可能锁定了电话.>当来自AAA的呼叫到达时,将使用带有应答按钮的视频ui打开该应用程序.就像在WhatsApp,GoogleDuo,Skype中一样…

我正在尝试通过Twilio视频通话提供本地视频通话体验.这是场景:

>人AAA呼叫人BBB.
>人员BBB没有打开应用程序,在后台或前景中,应用程序处于杀死状态,甚至可能锁定了电话.
>当来自AAA的呼叫到达时,将使用带有应答按钮的视频ui打开该应用程序.就像在WhatsApp,Google Duo,Skype中一样…

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

我们试图让服务在后台运行并打开一个套接字.当向套接字发出传入呼叫事件时,套接字将监听传入的呼叫并打开VIDeoCallActivity.

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

解决方法:

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

> 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类中,使用Intent启动VIDeoCall活动.不要忘记将此服务添加到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()的开头具有以下代码:

// 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 screenPowerManager 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 lockKeyguardManager keyguardManager = (KeyguardManager) getApplicationContext().getSystemService(Context.KEyguard_SERVICE);KeyguardManager.keyguardlock keyguardlock = keyguardManager.newkeyguardlock("TAG");keyguardlock.disableKeyguard();

>使用相应的intent-filter将VIDeoCallActivity添加到Manifest.xml中:

<!-视频通话->
<活动
    androID:name =“.ui.activitIEs.vIDeo_call.VIDeoCallActivity”
    androID:launchMode =“ singletop”
    androID:screenorIEntation =“ portrait”
    androID:theme =“ @ style / Apptheme.NoActionbar”>
    <意图过滤器>
        <!-注意:这些动作是通知动作->
        < action androID:name =“ VIDEO_CALliNG” />
        < category androID:name =“ androID.intent.category.DEFAulT” />
    < / intent-filter>
< / activity>

可选的:
要使电话响起并振动:

// For Incoming Call// 1. declareprivate 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 playerincomingCallMediaPlayer.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. declareprivate MediaPlayer callingMediaPlayer;// 2. in onCreate, if I'm being called, ring the phonecallingMediaPlayer = 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 soundcallingMediaPlayer.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视频通话,唤醒应用程序并进入前台全部内容,希望文章能够帮你解决Android Twilio视频通话,唤醒应用程序并进入前台所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1092160.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存