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

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

> 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值