键盘ai角色,无数据显示2

This commit is contained in:
pengxiaolong
2026-02-12 19:40:32 +08:00
parent ea2ec19dc8
commit acf4d39892
47 changed files with 1923 additions and 472 deletions

View File

@@ -13,6 +13,7 @@ import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.myapplication.network.BehaviorReporter
import com.example.myapplication.utils.ImeUtils
class ImeGuideActivity : AppCompatActivity() {
@@ -228,56 +229,7 @@ class ImeGuideActivity : AppCompatActivity() {
}
}
/** 是否启用了本输入法 */
private fun isImeEnabled(): Boolean {
return try {
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
val myComponent = ComponentName(this, MyInputMethodService::class.java)
val result = imm.enabledInputMethodList.any { imeInfo ->
imeInfo.packageName == myComponent.packageName &&
imeInfo.serviceName == myComponent.className
}
Log.d(TAG, "isImeEnabled = $result")
result
} catch (e: Exception) {
Log.e(TAG, "isImeEnabled 出错", e)
false
}
}
private fun isImeEnabled(): Boolean = ImeUtils.isImeEnabled(this)
/** 是否已切换为当前输入法 */
private fun isImeSelected(): Boolean {
return try {
val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
val myComponent = ComponentName(this, MyInputMethodService::class.java)
val currentImeId = Settings.Secure.getString(
contentResolver,
Settings.Secure.DEFAULT_INPUT_METHOD
) ?: return false
Log.d(TAG, "DEFAULT_INPUT_METHOD = $currentImeId")
// 找到“当前默认 IME”对应的 InputMethodInfo
val currentImeInfo = imm.enabledInputMethodList.firstOrNull { imeInfo ->
imeInfo.id == currentImeId
}
if (currentImeInfo == null) {
Log.d(TAG, "currentImeInfo == null")
return false
}
val isMine = currentImeInfo.packageName == myComponent.packageName &&
currentImeInfo.serviceName == myComponent.className
Log.d(TAG, "isImeSelected = $isMine")
isMine
} catch (e: Exception) {
Log.e(TAG, "isImeSelected 出错", e)
false
}
}
private fun isImeSelected(): Boolean = ImeUtils.isImeSelected(this)
}