feat(sdk-license): LicenseInitializerProvider 自动完成全量 SDK 初始化
ContentProvider 在 Application.onCreate() 之前运行,读取 assets/xuqm/license.xuqm 后直接调用 XuqmSDK.initialize()。 app 端只需放入 license 文件,无需任何初始化代码。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
84eeecb4cc
当前提交
63797ea1cb
@ -4,10 +4,20 @@ import android.content.ContentProvider
|
|||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import com.xuqm.sdk.XuqmSDK
|
||||||
|
|
||||||
class LicenseInitializerProvider : ContentProvider() {
|
class LicenseInitializerProvider : ContentProvider() {
|
||||||
override fun onCreate(): Boolean {
|
override fun onCreate(): Boolean {
|
||||||
context?.let(LicenseContextHolder::init)
|
val ctx = context ?: return true
|
||||||
|
LicenseContextHolder.init(ctx)
|
||||||
|
// Auto-initialize the full SDK if a license file is present in assets/xuqm/.
|
||||||
|
// Runs before Application.onCreate(), so no app-level init code is needed.
|
||||||
|
runCatching {
|
||||||
|
val licenseFile = LicenseFileReader.read(ctx) ?: return@runCatching
|
||||||
|
val appKey = licenseFile.appKey.takeIf { it.isNotBlank() } ?: return@runCatching
|
||||||
|
val serverUrl = licenseFile.serverUrl?.takeIf { it.isNotBlank() }
|
||||||
|
XuqmSDK.initialize(ctx, appKey, serverUrl)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户