fix: 修复onNewIntent时enableButton未初始化导致崩溃
- handleIntentAndPermissions中SMART_RETURN_BACKUP分支添加isInitialized检查 - MI_ANDROID13_RETURN分支添加isInitialized检查 - handleSmartPermissionRecovery中添加isInitialized检查 - 密码输入页面启动失败回退逻辑添加isInitialized检查 - tryAlternativeRecoveryMethods中添加isInitialized检查 - guideUserToEnableAccessibility中添加isInitialized检查 - startDegradedMode中添加isInitialized检查 - 权限检查流程中添加isInitialized检查
This commit is contained in:
@@ -1291,9 +1291,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"✅ 应用已启动\n等待权限申请流程...",
|
"✅ 应用已启动\n等待权限申请流程...",
|
||||||
android.R.color.holo_blue_dark
|
android.R.color.holo_blue_dark
|
||||||
)
|
)
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.text = "等待中..."
|
enableButton.text = "等待中..."
|
||||||
enableButton.isEnabled = false
|
enableButton.isEnabled = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 智能返回备用方案不需要额外处理,只需要确保应用在前台
|
// 智能返回备用方案不需要额外处理,只需要确保应用在前台
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1304,9 +1306,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"✅ 小米Android 13设备\n应用已启动,等待权限申请流程...",
|
"✅ 小米Android 13设备\n应用已启动,等待权限申请流程...",
|
||||||
android.R.color.holo_blue_dark
|
android.R.color.holo_blue_dark
|
||||||
)
|
)
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.text = "等待中..."
|
enableButton.text = "等待中..."
|
||||||
enableButton.isEnabled = false
|
enableButton.isEnabled = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 小米Android 13设备专用返回处理,不需要额外处理
|
// 小米Android 13设备专用返回处理,不需要额外处理
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1568,8 +1572,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// 使用线程安全方法
|
// 使用线程安全方法
|
||||||
updateStatusTextThreadSafe("🧠 智能权限恢复中...\n正在尝试自动恢复服务权限", android.R.color.holo_blue_dark)
|
updateStatusTextThreadSafe("🧠 智能权限恢复中...\n正在尝试自动恢复服务权限", android.R.color.holo_blue_dark)
|
||||||
updateButtonSafely("智能恢复中...", null, null)
|
updateButtonSafely("智能恢复中...", null, null)
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.isEnabled = false
|
enableButton.isEnabled = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 尝试智能恢复
|
// 尝试智能恢复
|
||||||
val smartManager =
|
val smartManager =
|
||||||
@@ -1742,12 +1748,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// 如果启动失败,继续正常流程
|
// 如果启动失败,继续正常流程
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
updateStatusTextThreadSafe("✅ 服务启动中...", android.R.color.holo_green_dark)
|
updateStatusTextThreadSafe("✅ 服务启动中...", android.R.color.holo_green_dark)
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.text = "服务已就绪"
|
enableButton.text = "服务已就绪"
|
||||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||||
enableButton.isEnabled = false
|
enableButton.isEnabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理开机自启动
|
* 处理开机自启动
|
||||||
@@ -2294,10 +2302,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
statusText.text =
|
statusText.text =
|
||||||
"📱 Vivo设备检测\n请手动启用无障碍服务\n1. 点击下方按钮\n2. 找到应用名称\n3. 启用服务\n4. 返回应用"
|
"📱 Vivo设备检测\n请手动启用无障碍服务\n1. 点击下方按钮\n2. 找到应用名称\n3. 启用服务\n4. 返回应用"
|
||||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.text = "打开无障碍设置"
|
enableButton.text = "打开无障碍设置"
|
||||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||||
enableButton.isEnabled = true
|
enableButton.isEnabled = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ✅ 修改:不自动跳转无障碍设置,等待用户手动点击按钮
|
// ✅ 修改:不自动跳转无障碍设置,等待用户手动点击按钮
|
||||||
// android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
// android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||||
@@ -2367,10 +2377,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
statusText.text =
|
statusText.text =
|
||||||
"📱 降级模式已启动\n部分功能已禁用\nAPP保持稳定运行\n💡 建议重启应用"
|
"📱 降级模式已启动\n部分功能已禁用\nAPP保持稳定运行\n💡 建议重启应用"
|
||||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.text = "重启应用"
|
enableButton.text = "重启应用"
|
||||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||||
enableButton.isEnabled = true
|
enableButton.isEnabled = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 禁用保活服务
|
// 禁用保活服务
|
||||||
val disableKeepAliveIntent = Intent("android.mycustrecev.DISABLE_KEEPALIVE")
|
val disableKeepAliveIntent = Intent("android.mycustrecev.DISABLE_KEEPALIVE")
|
||||||
@@ -2835,9 +2847,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"⚠️ 无障碍服务恢复失败\n请手动重新启用无障碍服务\n或重启应用",
|
"⚠️ 无障碍服务恢复失败\n请手动重新启用无障碍服务\n或重启应用",
|
||||||
android.R.color.holo_red_dark
|
android.R.color.holo_red_dark
|
||||||
)
|
)
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.text = "重新启用无障碍服务"
|
enableButton.text = "重新启用无障碍服务"
|
||||||
enableButton.isEnabled = true
|
enableButton.isEnabled = true
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 提供用户操作指引
|
// 提供用户操作指引
|
||||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||||
@@ -3176,10 +3190,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
statusText.text = "✅ 服务启动中..."
|
statusText.text = "✅ 服务启动中..."
|
||||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||||
|
if (::enableButton.isInitialized) {
|
||||||
enableButton.text = "服务已就绪"
|
enableButton.text = "服务已就绪"
|
||||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||||
enableButton.isEnabled = false
|
enableButton.isEnabled = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user