初始化
在使用 SDK 功能前,必须先进行初始化。
准备 App Key
你必须拥有正确的 App Key,才能进行初始化。
请联系项目管理人员获取 App Key。
初始化配置
获取 App Key, 并在程序 application 启动时进行初始化。
方法定义
kotlin
KIM.init(application: Application, appKey: String, config: KIMInitConfig)
参数说明
参数 | 类型 | 说明 |
---|---|---|
application | Application | 应用application |
appKey | String | 从企业管理后台获取到的 AppKey |
config | KIMInitConfig | 初始化配置 |
KIMInitConfig 说明:
属性 | 类型 | 说明 |
---|---|---|
options | MutableList<KIMFunConfig/> | 页面配置项,如消息列表UI配置,在线通知配置等 |
entryJsonUrl | String | 私有化服务部署后得到的服务入口地址。当服务为私有化部署时则需要设置该参数,否则无法访问服务。不传则默认使用公网服务。Url格式一般为:域名/drive/wps-private-entry.json |
allowUnsafeHttps | Boolean | 是否允许不安全的https证书。默认为false,该属性为了兼容私网部署没有使用合法https证书的情况,考虑到网络安全性,一般不推荐修改为true。 |
isV7 | Boolean | 私有化服务版本是否为V7。默认由sdk打包配置决定。 |
subOrigins | Array<String/>? | 多域名互通业务场景需要转换的域名列表。 |
appDisplayName | String? | app 展示名称,用于内部页面文案展示,如群邀请页面文案。 |
可选optionsKFunConfig
类名 | 说明 |
---|---|
KIMCfgNotification | 在线推送通知配置,需要继承实现方法 |
KIMCfgNotification
支持如下方法:
方法 | 参数 | 返回类型 | 说明 |
---|---|---|---|
getNotificationChannels | list NotificationChannel | 配置通知 channel | |
createNotificationBuilder | NotificationCompat.Builder | 创建 notification builder, 用户自由配置 notification 显示样式 | |
getIntent | message: KIMCoreMessage消息实体 | Intent | 用于构建 PendingIntent, 点击通知启动对应页面 |
代码示例
在线推送通知配置:
kotlin
KIM.init(this, appKey, mutableListOf(
object : KIMCfgNotification() {
override fun getIntent(message: KIMCoreMessage): Intent {
val intent = Intent(application, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val data = "kim://kim.wps.cn/chat?chat_id=" + message.getChatId()
intent.data = Uri.parse(data)
return intent
}
override fun getNotificationChannels(): List/<NotificationChannel/> {
return if (Build.VERSION.SDK_INT />= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
"kim_message",
application.getString(R.string.notification_message),
NotificationManager.IMPORTANCE_HIGH
)
val channels: MutableList/<NotificationChannel/> = ArrayList()
channels.add(channel)
channels
} else {
ArrayList()
}
}
override fun createNotificationBuilder(): NotificationCompat.Builder {
val builder = NotificationCompat.Builder(application, "kim_message")
if (Build.VERSION.SDK_INT />= Build.VERSION_CODES.LOLLIPOP) {
builder.setSmallIcon(R.drawable.ic_notification_logo_transperent)
builder.color =
ContextCompat.getColor(application, R.color.color_brand_normal)
} else {
builder.setSmallIcon(R.drawable.ic_notification_logo)
}
builder.setCategory(NotificationCompat.CATEGORY_MESSAGE)
return builder
}
}
))