我有这样的错误:“类型不匹配:推断的类型是字符串?但应该是字符串”
这是我的功能:
fun updateIcon(name: String) {
val context = MainActivity.appContext
val packageName: String = context.getPackageName()
val className: String = String.format("%s.%s", packageName, name)
val oldName: Array<ActivityInfo>? = getActivities()
val pm: PackageManager = context.getPackageManager()
pm.setComponentEnabledSetting(ComponentName(packageName, className), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
for(activity: ActivityInfo in oldName.orEmpty()) {
if(!activity.name.equals(className)) {
pm.setComponentEnabledSetting(ComponentName(packageName, activity.name), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
}
}
}
这是我使用它的地方:
val channelChangeAppIcon = "flutter.native/channelChangeAppIcon"
MethodChannel(flutterEngine.dartExecutor, channelChangeAppIcon).setMethodCallHandler { call, result ->
if (call.method == "updateIcon") {
try {
val str: String = call.argument<String>("name")
updateIcon(str) // here
result.success(true)
} catch (e: Exception) {
e.printStackTrace()
}
} else {
result.notImplemented()
}
}
提前致谢。