Impossible d'activer les notifications flottantes

Basouli -  
baba83500 Messages postés 2 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

J'ai épluché internet entier, anglais compris, pour résoudre mon problème sans succès :
Je n'arrive pas à coder une notification flottante et lockScreen. J'arrive à coder une notification qui apparait dans le fil de notif' seulement. j'ai mit cette permission "<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />"

Voici mon code :

NotificationManager notificationManager = activity.getSystemService(NotificationManager.class);

NotificationChannel channel = new NotificationChannel("timeAlert", "timeAlert", NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("visible in all way possible");
channel.setImportance(NotificationManager.IMPORTANCE_HIGH);
channel.setShowBadge(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
channel.setBypassDnd(true);
if (!notificationManager.getNotificationChannels().contains(channel)) {
    notificationManager.createNotificationChannel(channel);
}

Notification notification = new NotificationCompat.Builder(activity, "timeAlert")
    .setSmallIcon(R.drawable.logonotification)
    .setContentTitle("monTitre")
    .setContentText("monMessage")
    .setColor(activity.getResources().getColor(R.color.primary))
    .setColorized(true)
    .setPriority(NotificationManager.IMPORTANCE_MAX)
    .setDefaults(Notification.DEFAULT_ALL)
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setContentIntent(PendingIntent.getActivity(activity, 0, activity.getIntent(), 0))
    .setAutoCancel(true)
    .build();

notificationManager.notify(1, notification);


Le canal se créé bien, mais quand je vais voir ses paramètre, rien n'est coché.
Je code en Android Oreo 8.1 avec java 11.
Quelqu'un à une idée lumineuse ?

Configuration: Windows/ Firefox 94.0

3 réponses

lukas6410
 
il me semble que pour avoir une notification floottante il faut que tu renseigne une vue dans le notificationBuilder
0
BunoCS Messages postés 15952 Date d'inscription   Statut Modérateur Dernière intervention   3 918
 
Hello,

Qu'appelles-tu une "notification flottante" ?
A toute fin utile, le guide du développeur est ici : https://developer.android.com/training/notify-user/build-notification
0
baba83500 Messages postés 2 Date d'inscription   Statut Membre Dernière intervention  
 
J'ai pu résoudre ce problème partiellement :

L'appli n'avait en fait pas les autorisations ! Reste à savoir quel est le nom des autorisations concernées et comment les demander ?
0