Update: 2026-05-16 20:55:10

This commit is contained in:
Hamza-Ayed
2026-05-16 20:55:10 +03:00
parent 272eb768a0
commit b9d7a975b5
9 changed files with 40 additions and 4 deletions

View File

@@ -14,6 +14,8 @@ import android.view.accessibility.AccessibilityManager
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import android.net.Uri
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationManagerCompat
@@ -77,11 +79,23 @@ class MainActivity : AppCompatActivity() {
}
findViewById<Button>(R.id.btn_notification).setOnClickListener {
startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
showRestrictedSettingsDialog("صلاحية قراءة الإشعارات") {
startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS))
}
} else {
startActivity(Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS))
}
}
findViewById<Button>(R.id.btn_accessibility).setOnClickListener {
startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
showRestrictedSettingsDialog("صلاحية إمكانية الوصول") {
startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
}
} else {
startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS))
}
}
findViewById<Button>(R.id.btn_overlay).setOnClickListener {
@@ -204,4 +218,26 @@ class MainActivity : AppCompatActivity() {
btnStart.visibility = View.VISIBLE
btnStop.visibility = View.GONE
}
private fun showRestrictedSettingsDialog(permissionName: String, onProceed: () -> Unit) {
AlertDialog.Builder(this)
.setTitle("تفعيل $permissionName")
.setMessage("إذا وجدت الزر 'مغلق' أو بلون رمادي (Restricted Setting)، يرجى الضغط على زر 'فتح الإعدادات' أدناه، ثم الضغط على النقاط الثلاث في أعلى الصفحة واختيار 'Allow restricted settings' ثم العودة للتفعيل.\n\nهل تريد فتح الإعدادات الآن؟")
.setPositiveButton("فتح الإعدادات") { _, _ -> onProceed() }
.setNeutralButton("تعليمات فك القيد") { _, _ -> openAppInfo() }
.setNegativeButton("إلغاء", null)
.show()
}
private fun openAppInfo() {
try {
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
val uri = Uri.fromParts("package", packageName, null)
intent.data = uri
startActivity(intent)
Toast.makeText(this, "اضغط على النقاط الثلاث في الأعلى ثم Allow restricted settings", Toast.LENGTH_LONG).show()
} catch (e: Exception) {
Toast.makeText(this, "فشل فتح الإعدادات", Toast.LENGTH_SHORT).show()
}
}
}