Revert "Update .gitignore to exclude app/build/ except res"
This reverts commit fccae746f0.
This commit is contained in:
@@ -1076,13 +1076,6 @@ class MainActivity : AppCompatActivity() {
|
||||
* ✅ 统一的Intent处理方法
|
||||
*/
|
||||
private fun handleIntentAndPermissions(intent: Intent) {
|
||||
// ✅ 安全检查:确保UI组件已初始化(onNewIntent可能在initViews之前被调用)
|
||||
// 直接return,不尝试initViews()——Activity状态不确定时调用initViews()可能崩溃
|
||||
if (!::enableButton.isInitialized || !::statusText.isInitialized) {
|
||||
Log.w(TAG, "⚠️ UI组件未初始化,跳过handleIntentAndPermissions(Activity可能尚未完成onCreate)")
|
||||
return
|
||||
}
|
||||
|
||||
// 检查启动类型
|
||||
Log.i(TAG, "📋 检查启动参数和类型...")
|
||||
Log.i(
|
||||
@@ -1298,10 +1291,8 @@ class MainActivity : AppCompatActivity() {
|
||||
"✅ 应用已启动\n等待权限申请流程...",
|
||||
android.R.color.holo_blue_dark
|
||||
)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "等待中..."
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
enableButton.text = "等待中..."
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
// 智能返回备用方案不需要额外处理,只需要确保应用在前台
|
||||
}
|
||||
@@ -1313,10 +1304,8 @@ class MainActivity : AppCompatActivity() {
|
||||
"✅ 小米Android 13设备\n应用已启动,等待权限申请流程...",
|
||||
android.R.color.holo_blue_dark
|
||||
)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "等待中..."
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
enableButton.text = "等待中..."
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
// 小米Android 13设备专用返回处理,不需要额外处理
|
||||
}
|
||||
@@ -1578,7 +1567,8 @@ class MainActivity : AppCompatActivity() {
|
||||
// 显示非侵入式恢复状态
|
||||
// 使用线程安全方法
|
||||
updateStatusTextThreadSafe("🧠 智能权限恢复中...\n正在尝试自动恢复服务权限", android.R.color.holo_blue_dark)
|
||||
updateButtonSafely("智能恢复中...", null, false)
|
||||
updateButtonSafely("智能恢复中...", null, null)
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
|
||||
// 尝试智能恢复
|
||||
@@ -1752,11 +1742,9 @@ class MainActivity : AppCompatActivity() {
|
||||
// 如果启动失败,继续正常流程
|
||||
runOnUiThread {
|
||||
updateStatusTextThreadSafe("✅ 服务启动中...", android.R.color.holo_green_dark)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "服务已就绪"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
enableButton.text = "服务已就绪"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2054,10 +2042,10 @@ class MainActivity : AppCompatActivity() {
|
||||
*/
|
||||
private fun applyDefaultTexts() {
|
||||
try {
|
||||
if (::appNameText.isInitialized) appNameText.text = getString(R.string.app_name)
|
||||
if (::enableButton.isInitialized) enableButton.text = getString(R.string.enable_accessibility_service)
|
||||
if (::statusText.isInitialized) statusText.text = getString(R.string.service_status_checking)
|
||||
if (::usageInstructionsText.isInitialized) usageInstructionsText.text = getString(R.string.usage_instructions)
|
||||
appNameText.text = getString(R.string.app_name)
|
||||
enableButton.text = getString(R.string.enable_accessibility_service)
|
||||
statusText.text = getString(R.string.service_status_checking)
|
||||
usageInstructionsText.text = getString(R.string.usage_instructions)
|
||||
// 🔑 使用默认文本时不启用保护
|
||||
preserveCustomStatusText = false
|
||||
Log.i(TAG, "📝 已应用默认文字配置")
|
||||
@@ -2303,15 +2291,12 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "📱 引导用户到无障碍设置页面")
|
||||
|
||||
runOnUiThread {
|
||||
updateStatusTextSafely(
|
||||
"📱 Vivo设备检测\n请手动启用无障碍服务\n1. 点击下方按钮\n2. 找到应用名称\n3. 启用服务\n4. 返回应用",
|
||||
android.R.color.holo_orange_dark
|
||||
)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "打开无障碍设置"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text =
|
||||
"📱 Vivo设备检测\n请手动启用无障碍服务\n1. 点击下方按钮\n2. 找到应用名称\n3. 启用服务\n4. 返回应用"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
enableButton.text = "打开无障碍设置"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
|
||||
// ✅ 修改:不自动跳转无障碍设置,等待用户手动点击按钮
|
||||
@@ -2332,7 +2317,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔄 执行Vivo特定恢复策略")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔄 Vivo设备恢复中\n正在尝试多种恢复策略\n请稍候..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
}
|
||||
@@ -2352,7 +2336,6 @@ class MainActivity : AppCompatActivity() {
|
||||
if (recoveryHandler.recoverAccessibilityService()) {
|
||||
Log.i(TAG, "✅ Vivo无障碍服务恢复成功")
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "✅ Vivo设备恢复成功\n无障碍服务已正常运行"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
@@ -2381,15 +2364,12 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "📱 启动降级模式:禁用部分功能,保持APP稳定")
|
||||
|
||||
runOnUiThread {
|
||||
updateStatusTextSafely(
|
||||
"📱 降级模式已启动\n部分功能已禁用\nAPP保持稳定运行\n💡 建议重启应用",
|
||||
android.R.color.holo_orange_dark
|
||||
)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "重启应用"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text =
|
||||
"📱 降级模式已启动\n部分功能已禁用\nAPP保持稳定运行\n💡 建议重启应用"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
enableButton.text = "重启应用"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_orange_dark))
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
|
||||
// 禁用保活服务
|
||||
@@ -2855,10 +2835,8 @@ class MainActivity : AppCompatActivity() {
|
||||
"⚠️ 无障碍服务恢复失败\n请手动重新启用无障碍服务\n或重启应用",
|
||||
android.R.color.holo_red_dark
|
||||
)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "重新启用无障碍服务"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
enableButton.text = "重新启用无障碍服务"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
|
||||
// 提供用户操作指引
|
||||
@@ -2879,7 +2857,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
private fun updateUI() {
|
||||
// ✅ 安全检查:确保UI组件已初始化
|
||||
if (!::enableButton.isInitialized || !::statusText.isInitialized) {
|
||||
if (!::enableButton.isInitialized) {
|
||||
Log.w(TAG, "⚠️ UI组件未初始化,跳过updateUI")
|
||||
return
|
||||
}
|
||||
@@ -2953,10 +2931,8 @@ class MainActivity : AppCompatActivity() {
|
||||
"⚠️ 服务启动较慢\n💡 请尝试重新打开应用\n🔄 或点击按钮重新检查",
|
||||
android.R.color.holo_orange_dark
|
||||
)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "重新检查状态"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
enableButton.text = "重新检查状态"
|
||||
enableButton.isEnabled = true
|
||||
updateSwitchState()
|
||||
}
|
||||
}
|
||||
@@ -3198,12 +3174,11 @@ class MainActivity : AppCompatActivity() {
|
||||
// 删除悬浮窗权限申请,直接显示就绪状态
|
||||
Log.i(TAG, "🔧 跳过悬浮窗权限申请")
|
||||
runOnUiThread {
|
||||
updateStatusTextSafely("✅ 服务启动中...", android.R.color.holo_green_dark)
|
||||
if (::enableButton.isInitialized) {
|
||||
enableButton.text = "服务已就绪"
|
||||
enableButton.setBackgroundColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
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
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -3214,7 +3189,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.w(TAG, "⚠️ 无障碍截图只能单次截图,实时投屏需要MediaProjection权限")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "⚠️ 检测到权限配置不完整\n正在自动申请服务权限..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -3347,7 +3321,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🧠 启动智能权限申请流程")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🧠 检测到权限流程异常\n正在智能恢复权限申请..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
}
|
||||
@@ -3364,7 +3337,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔧 启动AccessibilityService故障恢复机制")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 检测到无障碍服务可能出现故障\n正在等待服务恢复..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -3387,7 +3359,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "✅ AccessibilityService已恢复,启动智能权限申请")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "✅ 无障碍服务已恢复\n开始智能权限申请..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
@@ -3405,7 +3376,6 @@ class MainActivity : AppCompatActivity() {
|
||||
val remainingTime = (remainingChecks * checkInterval) / 1000
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 等待无障碍服务恢复...\n" +
|
||||
"第${checkCount}次检测,剩余${remainingChecks}次\n" +
|
||||
"预计还需${remainingTime}秒,请稍候"
|
||||
@@ -3434,7 +3404,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.w(TAG, "⚠️ AccessibilityService恢复超时,提供备用权限申请方案")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "⚠️ 无障碍服务长时间无响应\n尝试备用权限申请方案..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
@@ -3444,7 +3413,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔄 启动备用权限申请:直接申请MediaProjection权限")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔄 启动备用服务权限申请方案\n正在申请服务权限..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
}
|
||||
@@ -3545,7 +3513,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 更新UI状态
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 正在申请所有权限...\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -3562,7 +3529,6 @@ class MainActivity : AppCompatActivity() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 发送所有权限申请广播失败", e)
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "❌ 广播发送失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
@@ -3578,7 +3544,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 更新UI状态
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 正在申请所有权限...\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -3651,14 +3616,12 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 更新UI状态
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 正在申请权限: ${permissionNames.joinToString(", ")}\n请一次性允许所有权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "✅ 所有权限已授予,无需申请")
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "✅ 所有权限已授予\n无需申请"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
@@ -3667,7 +3630,6 @@ class MainActivity : AppCompatActivity() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 收集权限列表失败", e)
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "❌ 权限收集失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
@@ -3677,7 +3639,6 @@ class MainActivity : AppCompatActivity() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 一次性权限申请失败", e)
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "❌ 权限申请失败\n请重试"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
}
|
||||
@@ -3803,7 +3764,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 方法1:确保Activity处于最佳状态
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 正在为设备优化权限申请...\n使用简化权限申请方法"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -3870,7 +3830,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.i(TAG, "🔧 MIUI设备使用内置权限申请方法")
|
||||
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 尝试内置权限申请方法..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -3919,7 +3878,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 方法6:更新UI状态
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text =
|
||||
"📱 请在弹出的权限对话框中点击\"立即开始\"\n如果没有看到对话框,请稍等片刻"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
@@ -3936,7 +3894,6 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 失败时回退到普通方法
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "⚠️ 优化失败,尝试标准方法...\n正在重新申请权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -4205,12 +4162,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 显示恢复成功状态
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "✅ 权限已存在,恢复完成\n功能正常运行"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "恢复完成"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
statusText.text = "✅ 权限已存在,恢复完成\n功能正常运行"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "恢复完成"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
|
||||
// 2秒后隐藏
|
||||
@@ -4313,7 +4268,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.w(TAG, "❌ SimplePermissionActivity返回失败")
|
||||
// 回退到内置方法
|
||||
runOnUiThread {
|
||||
if (!::statusText.isInitialized) return@runOnUiThread
|
||||
statusText.text = "🔧 独立Activity失败,尝试内置方法...\n正在重新申请权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
@@ -4434,12 +4388,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 显示恢复成功状态
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "✅ 权限恢复成功\n功能已恢复"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "恢复完成"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
statusText.text = "✅ 权限恢复成功\n功能已恢复"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "恢复完成"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
|
||||
// 3秒后隐藏界面
|
||||
@@ -4543,12 +4495,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// ✅ 显示权限申请成功状态,给用户反馈
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "✅ 权限申请成功\n正在启动服务..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "权限申请成功"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
statusText.text = "✅ 权限申请成功\n正在启动服务..."
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "权限申请成功"
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
|
||||
// ✅ 根据悬浮窗权限开关决定后续流程
|
||||
@@ -4558,10 +4508,8 @@ class MainActivity : AppCompatActivity() {
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||
if (!isFinishing) {
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "✅ 服务启动中...\n🔄 正在处理配置中"
|
||||
enableButton.text = "服务启动中..."
|
||||
}
|
||||
statusText.text = "✅ 服务启动中...\n🔄 正在处理配置中"
|
||||
enableButton.text = "服务启动中..."
|
||||
}
|
||||
}
|
||||
}, 1500) // 1.5秒后更新状态
|
||||
@@ -4570,13 +4518,11 @@ class MainActivity : AppCompatActivity() {
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||
if (!isFinishing) {
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}, 5000) // 5秒后显示最终成功状态
|
||||
@@ -5168,12 +5114,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
// 更新UI状态
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "📷 正在申请摄像头权限\n请在弹出的对话框中点击允许"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
enableButton.text = "申请中..."
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
statusText.text = "📷 正在申请摄像头权限\n请在弹出的对话框中点击允许"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_blue_dark))
|
||||
enableButton.text = "申请中..."
|
||||
enableButton.isEnabled = false
|
||||
}
|
||||
|
||||
// 申请摄像头权限
|
||||
@@ -5182,12 +5126,10 @@ class MainActivity : AppCompatActivity() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "❌ 处理摄像头权限申请请求失败", e)
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "❌ 摄像头权限申请失败\n请手动在设置中开启"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
enableButton.text = "重试"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text = "❌ 摄像头权限申请失败\n请手动在设置中开启"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
enableButton.text = "重试"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5232,12 +5174,10 @@ class MainActivity : AppCompatActivity() {
|
||||
} else {
|
||||
Log.i(TAG, "✅ 摄像头权限已授予")
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "✅ 摄像头权限已授予\n权限申请完成"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "完成"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text = "✅ 摄像头权限已授予\n权限申请完成"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "完成"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
|
||||
// 延迟隐藏Activity
|
||||
@@ -5248,12 +5188,10 @@ class MainActivity : AppCompatActivity() {
|
||||
} else {
|
||||
Log.i(TAG, "✅ Android版本低于6.0,无需申请摄像头权限")
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "✅ Android版本低于6.0\n无需申请摄像头权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "完成"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text = "✅ Android版本低于6.0\n无需申请摄像头权限"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "完成"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
|
||||
// 延迟隐藏Activity
|
||||
@@ -5264,12 +5202,10 @@ class MainActivity : AppCompatActivity() {
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "申请摄像头权限失败", e)
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "❌ 摄像头权限申请失败\n请手动在设置中开启"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
enableButton.text = "重试"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text = "❌ 摄像头权限申请失败\n请手动在设置中开启"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
enableButton.text = "重试"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5321,12 +5257,10 @@ class MainActivity : AppCompatActivity() {
|
||||
if (allGranted) {
|
||||
Log.i(TAG, "✅ 摄像头权限已授予")
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "✅ 摄像头权限已授予\n权限申请完成"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "完成"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text = "✅ 摄像头权限已授予\n权限申请完成"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
enableButton.text = "完成"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
|
||||
// 延迟隐藏Activity
|
||||
@@ -5336,12 +5270,10 @@ class MainActivity : AppCompatActivity() {
|
||||
} else {
|
||||
Log.w(TAG, "❌ 摄像头权限被拒绝")
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized && ::enableButton.isInitialized) {
|
||||
statusText.text = "❌ 摄像头权限被拒绝\n请手动在设置中开启"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
enableButton.text = "重试"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
statusText.text = "❌ 摄像头权限被拒绝\n请手动在设置中开启"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_red_dark))
|
||||
enableButton.text = "重试"
|
||||
enableButton.isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5356,18 +5288,14 @@ class MainActivity : AppCompatActivity() {
|
||||
if (allGranted) {
|
||||
Log.i(TAG, "✅ 所有权限已授予")
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "✅ 所有权限已授予\n权限申请完成"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
statusText.text = "✅ 所有权限已授予\n权限申请完成"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_green_dark))
|
||||
}
|
||||
} else {
|
||||
Log.w(TAG, "⚠️ 部分权限被拒绝: $grantedCount/$totalCount")
|
||||
runOnUiThread {
|
||||
if (::statusText.isInitialized) {
|
||||
statusText.text = "⚠️ 部分权限被拒绝\n已授予: $grantedCount/$totalCount"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
statusText.text = "⚠️ 部分权限被拒绝\n已授予: $grantedCount/$totalCount"
|
||||
statusText.setTextColor(getColor(android.R.color.holo_orange_dark))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user