Android12上Twilio视频后台模式停止工作
创始人
2024-09-30 21:00:33
0

问题来源于 Android 12 更严格的后台限制。应用在后台运行时,Twilio Video SDK 通过启用后台服务来维持其会话,并且在 Android 12 上需要满足额外的条件。

解决方法是使用新的后台服务 API,并修改 Twilio Video SDK 的代码以适应 Android 12 的后台限制。以下是一个示例代码,演示如何在 Android 12 上保持 Twilio Video 会话:

// Manifest Declare Service

// Service Code public class NotificationService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { startForeground(NOTIFICATION_ID, new Notification()); stopForeground(true); return START_NOT_STICKY; }

@Override public IBinder onBind(Intent intent) { return null; } }

// MainActivity Code private fun createNotification() { val notification = Notification.Builder(this, channelId) .setContentTitle("Title") .setContentText("Text") .setSmallIcon(R.drawable.icon)

val intent = Intent(this, TwilioVideoService::class.java) intent.putExtra(TwilioVideoService.EXTRA_NOTIFICATION_STOP, true) val pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)

notification.addAction(Notification.Action.Builder( Icon.createWithResource(this, R.drawable.stop), "Stop", pendingIntent).build())

startForeground(NOTIFICATION_ID, notification.build())

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { // startForegroundService does not set the foreground notification icon on Android API level >= 26 startService(Intent(this, NotificationService::class.java)) } }

// TwilioVideoService Code override fun onBind(intent: Intent?): IBinder? = null

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { if (intent?.getBooleanExtra(EXTRA_NOTIFICATION_STOP, false) == true) { stopForeground(true

相关内容

热门资讯

玩家实测!fishpoker透... 玩家实测!fishpoker透视底牌,xpoker透视辅助,分享教程(有挂技巧)1、点击下载安装,微...
揭秘几款!hhpoker有辅助... 1、揭秘几款!hhpoker有辅助吗,wepoker脚本下载,第三方教程(有挂辅助);详细教程。2、...
总算清楚!wepoker祈福有... 总算清楚!wepoker祈福有用吗,wepoker私人局怎么玩,攻略教程(有挂方法);玩家必备必赢加...
记者揭秘!aapoker辅助怎... 记者揭秘!aapoker辅助怎么用,hhpoker是真的还是假的,专业教程(有挂技巧);hhpoke...
盘点一款!epoker透视底牌... 1、盘点一款!epoker透视底牌,大菠萝免费辅助,详细教程(有挂辅助);详细教程。2、大菠萝免费辅...
重大通报!wepoker高级辅... 1、重大通报!wepoker高级辅助,wepoker国外版透视,规律教程(有挂技巧);详细教程。2、...
一秒答解!wepoker究竟有... 一秒答解!wepoker究竟有没有透视,hhpoker脚本下载,介绍教程(有挂透明);建议优先通过w...
每日必备!aapoker公共底... 1、每日必备!aapoker公共底牌,wepoker底牌透视脚本,攻略方法(有挂软件)(UU pok...
今日百科!wepoker破解游... 今日百科!wepoker破解游戏盒子,hardrock透视工具,新2025教程(有挂软件)是由北京得...
1.9分钟了解!wepoker... 自定义wepoker私人局俱乐部辅助系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专...