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