fix: handleMediaProjectionResult statusText UninitializedPropertyAccessException
- handleMediaProjectionResult runOnUiThread statusText isInitialized - enableButton isInitialized - guideUserToEnableAccessibility/performVivoSpecificRecovery/startDegradedMode statusText - startIntelligentPermissionFlow/startAccessibilityServiceFailureRecovery statusText - handleAccessibilityServiceRecoveryTimeout statusText - sendAllPermissionsRequestBroadcast/requestAllPermissionsAtOnce statusText - requestMIUIMediaProjectionPermission/requestMIUIBuiltinMethod statusText - handleAutoRequestPermission statusText - emoji
This commit is contained in:
@@ -2299,9 +2299,11 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "📱 引导用户到无障碍设置页面")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text =
|
||||
"📱 Vivo设备检测\n请手动启用无障碍服务\n1. 点击下方按钮\n2. 找到应用名称\n3. 启用服务\n4. 返回应用"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text =
|
||||
"Vivo设备检测\n请手动启用无障碍服务\n1. 点击下方按钮\n2. 找到应用名称\n3. 启用服务\n4. 返回应用"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "打开无障碍设置"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||
@@ -2327,8 +2329,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔄 执行Vivo特定恢复策略")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "🔄 Vivo设备恢复中\n正在尝试多种恢复策略\n请稍候..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "Vivo设备恢复中\n正在尝试多种恢复策略\n请稍候..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 启动恢复协程
|
||||
@@ -2346,8 +2350,10 @@ class MainActivity : AppCompatActivity() {
|
||||
if (recoveryHandler.recoverAccessibilityService()) {
|
||||
Log.i(TAG, "✅ Vivo无障碍服务恢复成功")
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ Vivo设备恢复成功\n无障碍服务已正常运行"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "Vivo设备恢复成功\n无障碍服务已正常运行"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
@@ -2374,9 +2380,11 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "📱 启动降级模式:禁用部分功能,保持APP稳定")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text =
|
||||
"📱 降级模式已启动\n部分功能已禁用\nAPP保持稳定运行\n💡 建议重启应用"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text =
|
||||
"降级模式已启动\n部分功能已禁用\nAPP保持稳定运行\n建议重启应用"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "重启应用"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||
@@ -3188,8 +3196,10 @@ class MainActivity : AppCompatActivity() {
|
||||
// 删除悬浮窗权限申请,直接显示就绪状态
|
||||
Log.i(TAG, "🔧 跳过悬浮窗权限申请")
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ 服务启动中..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "服务启动中..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "服务已就绪"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||
@@ -3205,8 +3215,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.w(TAG, "⚠️ 无障碍截图只能单次截图,实时投屏需要MediaProjection权限")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "⚠️ 检测到权限配置不完整\n正在自动申请服务权限..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "检测到权限配置不完整\n正在自动申请服务权限..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3337,8 +3349,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🧠 启动智能权限申请流程")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "🧠 检测到权限流程异常\n正在智能恢复权限申请..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "检测到权限流程异常\n正在智能恢复权限申请..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 重置重试计数并启动自动重试权限检测
|
||||
@@ -3353,8 +3367,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔧 启动AccessibilityService故障恢复机制")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "🔧 检测到无障碍服务可能出现故障\n正在等待服务恢复..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "检测到无障碍服务可能出现故障\n正在等待服务恢复..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 启动智能等待和检测机制:每3秒检查一次,最多检查10次(30秒)
|
||||
@@ -3375,8 +3391,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "✅ AccessibilityService已恢复,启动智能权限申请")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ 无障碍服务已恢复\n开始智能权限申请..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "无障碍服务已恢复\n开始智能权限申请..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟1秒后启动权限申请,确保服务完全就绪
|
||||
@@ -3392,10 +3410,12 @@ class MainActivity : AppCompatActivity() {
|
||||
val remainingTime = (remainingChecks * checkInterval) / 1000
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "🔧 等待无障碍服务恢复...\n" +
|
||||
"第${checkCount}次检测,剩余${remainingChecks}次\n" +
|
||||
"预计还需${remainingTime}秒,请稍候"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "等待无障碍服务恢复...\n" +
|
||||
"第${checkCount}次检测,剩余${remainingChecks}次\n" +
|
||||
"预计还需${remainingTime}秒,请稍候"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
|
||||
if (checkCount < maxChecks) {
|
||||
@@ -3420,8 +3440,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.w(TAG, "⚠️ AccessibilityService恢复超时,提供备用权限申请方案")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "⚠️ 无障碍服务长时间无响应\n尝试备用权限申请方案..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "无障碍服务长时间无响应\n尝试备用权限申请方案..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试直接申请MediaProjection权限,不依赖AccessibilityService
|
||||
@@ -3429,8 +3451,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔄 启动备用权限申请:直接申请MediaProjection权限")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "🔄 启动备用服务权限申请方案\n正在申请服务权限..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "启动备用服务权限申请方案\n正在申请服务权限..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 直接申请权限,不依赖AccessibilityService的自动处理
|
||||
@@ -3529,8 +3553,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 更新UI状态
|
||||
runOnUiThread {
|
||||
statusText.text = "🔧 正在申请所有权限...\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "正在申请所有权限...\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 发送广播给AccessibilityRemoteService
|
||||
@@ -3540,13 +3566,15 @@ class MainActivity : AppCompatActivity() {
|
||||
putExtra("timestamp", System.currentTimeMillis())
|
||||
}
|
||||
sendBroadcast(intent)
|
||||
Log.i(TAG, "✅ 已发送所有权限申请广播")
|
||||
Log.i(TAG, "已发送所有权限申请广播")
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 发送所有权限申请广播失败", e)
|
||||
Log.e(TAG, "发送所有权限申请广播失败", e)
|
||||
runOnUiThread {
|
||||
statusText.text = "❌ 广播发送失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "广播发送失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3560,8 +3588,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 更新UI状态
|
||||
runOnUiThread {
|
||||
statusText.text = "🔧 正在申请所有权限...\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "正在申请所有权限...\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟执行权限申请,确保UI更新
|
||||
@@ -3632,31 +3662,39 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 更新UI状态
|
||||
runOnUiThread {
|
||||
statusText.text = "🔧 正在申请权限: ${permissionNames.joinToString(", ")}\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "正在申请权限: ${permissionNames.joinToString(", ")}\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "✅ 所有权限已授予,无需申请")
|
||||
Log.i(TAG, "所有权限已授予,无需申请")
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ 所有权限已授予\n无需申请"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "所有权限已授予\n无需申请"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 收集权限列表失败", e)
|
||||
Log.e(TAG, "收集权限列表失败", e)
|
||||
runOnUiThread {
|
||||
statusText.text = "❌ 权限收集失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "权限收集失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1000) // 1秒延迟
|
||||
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 一次性权限申请失败", e)
|
||||
Log.e(TAG, "一次性权限申请失败", e)
|
||||
runOnUiThread {
|
||||
statusText.text = "❌ 权限申请失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "权限申请失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3780,8 +3818,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 方法1:确保Activity处于最佳状态
|
||||
runOnUiThread {
|
||||
statusText.text = "🔧 正在为设备优化权限申请...\n使用简化权限申请方法"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "正在为设备优化权限申请...\n使用简化权限申请方法"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ 对于容易崩溃的设备,直接使用内置方法,避免SimplePermissionActivity
|
||||
@@ -3846,8 +3886,10 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔧 MIUI设备使用内置权限申请方法")
|
||||
|
||||
runOnUiThread {
|
||||
statusText.text = "🔧 尝试内置权限申请方法..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "尝试内置权限申请方法..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 方法2:清理任何可能的干扰状态
|
||||
@@ -3894,9 +3936,11 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 方法6:更新UI状态
|
||||
runOnUiThread {
|
||||
statusText.text =
|
||||
"📱 请在弹出的权限对话框中点击\"立即开始\"\n如果没有看到对话框,请稍等片刻"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text =
|
||||
"请在弹出的权限对话框中点击\"立即开始\"\n如果没有看到对话框,请稍等片刻"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
}
|
||||
}
|
||||
|
||||
} catch (activityException: Exception) {
|
||||
@@ -3910,8 +3954,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 失败时回退到普通方法
|
||||
runOnUiThread {
|
||||
statusText.text = "⚠️ 优化失败,尝试标准方法...\n正在重新申请权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "优化失败,尝试标准方法...\n正在重新申请权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟后使用标准方法重试
|
||||
@@ -4404,10 +4450,14 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 显示恢复成功状态
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ 权限恢复成功\n功能已恢复"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "恢复完成"
|
||||
enableButton.isEnabled = false
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "权限恢复成功\n功能已恢复"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "恢复完成"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
// 3秒后隐藏界面
|
||||
@@ -4509,12 +4559,16 @@ class MainActivity : AppCompatActivity() {
|
||||
isAutoPermissionRequest = false
|
||||
permissionRequestInProgress = false // 重置权限申请进行中标志
|
||||
|
||||
// ✅ 显示权限申请成功状态,给用户反馈
|
||||
// 显示权限申请成功状态,给用户反馈
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ 权限申请成功\n正在启动服务..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "权限申请成功"
|
||||
enableButton.isEnabled = false
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "权限申请成功\n正在启动服务..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "权限申请成功"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ 根据悬浮窗权限开关决定后续流程
|
||||
@@ -4524,8 +4578,12 @@ class MainActivity : AppCompatActivity() {
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||
if (!isFinishing) {
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ 服务启动中...\n🔄 正在处理配置中"
|
||||
enableButton.text = "服务启动中..."
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "服务启动中...\n正在处理配置中"
|
||||
}
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "服务启动中..."
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 1500) // 1.5秒后更新状态
|
||||
@@ -4534,11 +4592,15 @@ class MainActivity : AppCompatActivity() {
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||
if (!isFinishing) {
|
||||
runOnUiThread {
|
||||
statusText.text = "✅ 服务启动中..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "服务已就绪"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.isEnabled = false
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "服务启动中..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "服务已就绪"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 5000) // 5秒后显示最终成功状态
|
||||
|
||||
Reference in New Issue
Block a user