Skip to content
能力中心
产品中心
应用市场
WebOffice
开发者后台

初始化

在使用 SDK 功能前,必须先进行初始化。

准备 App Key

你必须拥有正确的 App Key,才能进行初始化。

请联系项目管理人员获取 App Key。

初始化配置

获取 App Key, 并在程序 application 启动时进行初始化。

方法定义

kotlin
KIM.init(application: Application, appKey: String, config: KIMInitConfig)

参数说明

参数类型说明
applicationApplication应用application
appKeyString从企业管理后台获取到的 AppKey
configKIMInitConfig初始化配置

KIMInitConfig 说明:

属性类型说明
optionsMutableList<KIMFunConfig/>页面配置项,如消息列表UI配置,在线通知配置等
entryJsonUrlString私有化服务部署后得到的服务入口地址。当服务为私有化部署时则需要设置该参数,否则无法访问服务。不传则默认使用公网服务。Url格式一般为:域名/drive/wps-private-entry.json
allowUnsafeHttpsBoolean是否允许不安全的https证书。默认为false,该属性为了兼容私网部署没有使用合法https证书的情况,考虑到网络安全性,一般不推荐修改为true。
isV7Boolean私有化服务版本是否为V7。默认由sdk打包配置决定。
subOriginsArray<String/>?多域名互通业务场景需要转换的域名列表。
appDisplayNameString?app 展示名称,用于内部页面文案展示,如群邀请页面文案。

可选optionsKFunConfig

类名说明
KIMCfgNotification在线推送通知配置,需要继承实现方法

KIMCfgNotification支持如下方法:

方法参数返回类型说明
getNotificationChannelslist NotificationChannel配置通知 channel
createNotificationBuilderNotificationCompat.Builder创建 notification builder, 用户自由配置 notification 显示样式
getIntentmessage: 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
      }

}
))