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

相关内容

热门资讯

详细透视!werplan免费挂... 详细透视!werplan免费挂下载!原来一直都是有辅助教程(有挂解惑)-哔哩哔哩1、操作简单,无需w...
科普透视!epoker免费透视... 科普透视!epoker免费透视脚本!其实一直总是有辅助脚本(有挂教程)-哔哩哔哩epoker免费透视...
科普透视!红龙poker作必弊... 科普透视!红龙poker作必弊指令!真是真的是有辅助神器(今日头条)-哔哩哔哩1、用户打开应用后不用...
解密透视!竞技联盟辅助!一直是... 解密透视!竞技联盟辅助!一直是真的有辅助软件(有挂猫腻)-哔哩哔哩1、起透看视 竞技联盟辅助辅助软件...
分享透视!pokerworld... 分享透视!pokerworld修改器!确实存在有辅助方法(有挂分享)-哔哩哔哩亲,关键说明,poke...
了解透视!newpoker怎么... 了解透视!newpoker怎么安装脚本!都是真的是有辅助app(有挂技巧)-哔哩哔哩1、点击下载安装...
揭幕透视!哈糖大菠萝有挂吗!一... 揭幕透视!哈糖大菠萝有挂吗!一贯一直都是有辅助方法(有挂技巧)-哔哩哔哩1、超多福利:超高返利,海量...
解密透视!sohoo poke... 解密透视!sohoo poker辅助器!其实存在有辅助脚本(有挂教学)-哔哩哔哩1、完成sohoo ...
必备透视!佛手在线大菠萝智能辅... 您好,佛手在线大菠萝智能辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054...
揭露透视!约局吧透视挂下载!真... 揭露透视!约局吧透视挂下载!真是一直都是有辅助技巧(有挂头条)-哔哩哔哩1、下载好约局吧透视挂下载透...