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

我正在尝试通过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 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();

>使用相应的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. 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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...