消息Push Android接入方法
示意图

接入方式
直播消息push的能力在ILivePush接口中暴露,获取到该接口的实例就可以正常使用直播push相关能力
interface ILivePush {
......
/**
* 请求 push 数据并展示
* [needShow] 是否需要展示 UI,接入方可以根据需要自定义 UI
*/
fun requestPushAndShow(
needShow: Boolean,
activity: Activity,
pushType: PushType,
pushCallback: PushCallback? = null,
pushUIConfig: PushUIConfig? = null
)
/**
* 隐藏push
*/
fun dismiss()
......
}
使用示例
// 展示push示例
TTLiveService.getLiveService()?.livePush?.requestPushAndShow(
true,
Activity@ this,
ILivePush.PushType.SELF_DRIVING,
object: PushCallback {
override fun onSuccess(pushData: PushData?) {
}
override fun onFailed(throwable: Throwable) {
Toast.makeText(this@VirtualPushActivity, throwable.message, Toas
t.LENGTH_LONG).show()
}
},
null
)
//隐藏push示例
TTLiveService.getLiveService()?.livePush?.dismiss()
有些情况下,需要根据此时的上下文判断是否需要展示 Push。
fun addPushInterceptor(pushIntercept: PushInterceptor)
interface PushInterceptor {
/**
* 如果拦截则返回 True
*/
fun intercept(): InterceptResult
data class InterceptResult(val intercept: Boolean, val interceptReason: String = "")
}
示例代码
TTLiveService.getLiveService()?.livePush?.addPushInterceptor(object: PushInterceptor {
override fun intercept(): PushInterceptor.InterceptResult {
if (pushTestResult % 2 != 0) {
Toast.makeText(this@PushActivity, "拦截push,无法弹出 push", Toast.LENGT
H_LONG).show()
}
return PushInterceptor.InterceptResult(pushTestResult % 2 != 0, "宿主拦截")
}
})
参数说明
fun requestPushAndShow(
needShow: Boolean,
activity: Activity,
pushType: PushType,
pushCallback: PushCallback? = null,
pushUIConfig: PushUIConfig? = null
)
- needShow: 是否需要展示 push
- pushType:
- SELF_DRIVING(1), //宿主主动调用,不走频控逻辑
- CLOD_LAUNCH(2), // 冷启动调用
- VIDEO(3), //观看小视频,走频控逻辑
- pushCallback: 结果回调
- pushUIConfig:push 的 UI 样式
诚邀您对本文档易读易用性进行评价
好用
不好用