Procházet zdrojové kódy

Bouton « Ouvrir les réglages » : repli quand l'écran d'accès aux notifications n'existe pas

Cette ROM Wear (OPPO/Realme) n'expose pas l'intent systeme
ACTION_NOTIFICATION_LISTENER_SETTINGS (resolve-activity : aucune activite).
Le bouton lançait cet intent immédiatement : il ne faisait donc rien.

Ouvrir désormais, dans l'ordre, l'écran dédié aux écouteurs, puis la fiche
de l'application (ouviable sur cette montre), puis les réglages, en
avalent via try/catch l'absence d'écran. Signature retournant un booléen.

Vérifié sur montre (adb 192.168.64.132) : le tap ouvre bien la fiche app
(MainSettingsActivity), access aux notifications accordé via
'cmd notification allow_listener' (cette ROM n'a pas d'UI prévue).
aston před 1 měsícem
rodič
revize
c28900c34b

+ 18 - 0
AGENTS.md

@@ -60,6 +60,24 @@ java -jar /tmp/opencode/plantuml.jar -checkonly documentation/puml/*.puml
   analyse des pixels (voir `scripts/`), puis comparer avec le `NavHost`
   analyse des pixels (voir `scripts/`), puis comparer avec le `NavHost`
   standard `androidx.navigation.compose.NavHost` qui, lui, rend correctement.
   standard `androidx.navigation.compose.NavHost` qui, lui, rend correctement.
 
 
+## Accès aux notifications sur la montre réelle (OPPO/Realme, 10/2026)
+
+- L'intent système `Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS` **n'existe
+  pas** sur cette ROM (`cmd package resolve-activity` → *No activity found*).
+  Le bouton « Ouvrir les réglages » enchaîne donc un repli :
+  `APPLICATION_DETAILS_SETTINGS` → `SETTINGS`, via try/catch
+  `ActivityNotFoundException` (`NotificationAccess.kt`).
+- Conséquence : sur cette montre l'utilisateur ne peut probablement **pas**
+  activer l'accès aux notifications depuis l'UI. Pour les tests, l'activer via
+  adb (surveiller le `enabled_notification_listeners`) :
+  ```
+  adb shell cmd notification allow_listener \
+      fr.barteam.watchosm/fr.barteam.watchosm.data.OsmAndNotificationListener
+  adb shell settings get secure enabled_notification_listeners
+  ```
+- `cmd notification post` ne permet pas de choisir le package émetteur : on ne
+  peut pas simuler une notification OsmAnd par adb pour tester le listener.
+
 ## Diagrammes UML
 ## Diagrammes UML
 
 
 - Sources **uniquement** en PlantUML (`.puml`) dans `documentation/puml/`.
 - Sources **uniquement** en PlantUML (`.puml`) dans `documentation/puml/`.

+ 29 - 5
wear/src/main/java/fr/barteam/watchosm/ui/NotificationAccess.kt

@@ -1,7 +1,9 @@
 package fr.barteam.watchosm.ui
 package fr.barteam.watchosm.ui
 
 
+import android.content.ActivityNotFoundException
 import android.content.Context
 import android.content.Context
 import android.content.Intent
 import android.content.Intent
+import android.net.Uri
 import android.provider.Settings
 import android.provider.Settings
 import androidx.core.app.NotificationManagerCompat
 import androidx.core.app.NotificationManagerCompat
 
 
@@ -9,10 +11,32 @@ import androidx.core.app.NotificationManagerCompat
 fun isNotificationAccessEnabled(context: Context): Boolean =
 fun isNotificationAccessEnabled(context: Context): Boolean =
     NotificationManagerCompat.getEnabledListenerPackages(context).contains(context.packageName)
     NotificationManagerCompat.getEnabledListenerPackages(context).contains(context.packageName)
 
 
-/** Ouvre l'écran système de gestion de l'accès aux notifications. */
-fun openNotificationAccessSettings(context: Context) {
-    context.startActivity(
-        Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
-            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK),
+/**
+ * Ouvre l'écran de gestion de l'accès aux notifications.
+ *
+ * Wear OS n'expose pas toujours `ACTION_NOTIFICATION_LISTENER_SETTINGS` : selon
+ * la montre/la ROM, cet écran peut être absent. On tente donc, dans l'ordre,
+ * l'écran dédié aux écouteurs de notifications, puis la fiche de l'application
+ * (où l'utilisateur trouve l'accès aux notifications), puis les réglages.
+ *
+ * @return true si un écran a pu être ouvert.
+ */
+fun openNotificationAccessSettings(context: Context): Boolean {
+    val candidates = listOf(
+        Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS),
+        Intent(
+            Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
+            Uri.fromParts("package", context.packageName, null),
+        ),
+        Intent(Settings.ACTION_SETTINGS),
     )
     )
+    for (intent in candidates) {
+        try {
+            context.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
+            return true
+        } catch (_: ActivityNotFoundException) {
+            // Écran absent sur cette ROM : on essaie le suivant.
+        }
+    }
+    return false
 }
 }