Notification app ne fonctionne plus

Résolu/Fermé
Joker_ Messages postés 173 Date d'inscription mardi 13 octobre 2009 Statut Membre Dernière intervention 20 janvier 2023 - Modifié le 10 oct. 2018 à 14:37
Joker_ Messages postés 173 Date d'inscription mardi 13 octobre 2009 Statut Membre Dernière intervention 20 janvier 2023 - 16 oct. 2018 à 03:44
Bonjour,
j'ai créé une application qui sert à envoyer des notification vers le système.. elle a fonctionné bien dans mon téléphone samsung j5 prime. Hier mon téléphone a migré vers Android 8.0 alors que mon application ne fonctionne plus ainsi que mon icon de l'application personnalisé n'est plus aussi ( l'icon par défaut l'a remplacé)

Est ce que c'est normale???

j'ai ajouté avant la ligne implementation "me.leolin:ShortcutBadger:1.1.22@aar"
ainsi j'ai ajouté ces ligne après dependencies
repositories {
mavenCentral()
}
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import me.leolin.shortcutbadger.ShortcutBadger;

public class TutoNotificationHomeActivity extends Activity {
    private Button addNotificationBtn;
    private Button deleteNotificationBtn;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tuto_notification_home);
        addNotificationBtn = (Button) findViewById(R.id.add_notification);
        txtResult = (TextView) findViewById(R.id.txtResult);
        addNotificationBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Toast.makeText(getBaseContext(), "Ajout d'une notification", 2).show();
                createNotification();
            }
        });
        deleteNotificationBtn = (Button) findViewById(R.id.delete_notification);
        deleteNotificationBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Toast.makeText(getBaseContext(), "Suppression d'une notification", 2).show();
                deleteNotification();
            }
        });
    }

    private final void createNotification() {
        final NotificationManager mNotification = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        final Intent launchNotifiactionIntent = new Intent(this, TutoNotificationHomeActivity.class);
        final PendingIntent pendingIntent = PendingIntent.getActivity(this,
                1, launchNotifiactionIntent,
                PendingIntent.FLAG_ONE_SHOT);
        Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.URI_COLUMN_INDEX);
        Notification.Builder builder = new Notification.Builder(this)
                .setWhen(System.currentTimeMillis())
                .setTicker("New notification")
                .setSmallIcon(R.drawable.notification)
                .setContentTitle("This is a title")
                .setContentText("This is the a text")
                .setContentIntent(pendingIntent)
                .setSound(soundUri);
        mNotification.notify(1, builder.build());
        int badgeCount = 1;
        ShortcutBadger.applyCount(TutoNotificationHomeActivity.this, badgeCount);
    }

    private void deleteNotification() {
        final NotificationManager notificationManager = (NotificationManager)    getSystemService(NOTIFICATION_SERVICE);
        notificationManager.cancel(1);
        ShortcutBadger.applyCount(TutoNotificationHomeActivity.this,0); 
    }
}



A voir également:

3 réponses

BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 3 895
Modifié le 10 oct. 2018 à 14:42
Hello,

Rien de bizarre là dedans.
Si je regarde la doc de NotificationBuilder je vois que le constructeur que tu utilises est déprécié depuis l'api 26, c'est-à-dire Android Oreo. Il te faut indiquer un
channelId
pour les versions supérieures

1
Joker_ Messages postés 173 Date d'inscription mardi 13 octobre 2009 Statut Membre Dernière intervention 20 janvier 2023 1
10 oct. 2018 à 10:18
J'ai encore testé mon application dans un autre téléphone samsung grand prime Android 6 mais tous fonctionne bien!!! c'est bizarre!!!???
0
Joker_ Messages postés 173 Date d'inscription mardi 13 octobre 2009 Statut Membre Dernière intervention 20 janvier 2023 1
12 oct. 2018 à 23:57
merci bien pour la réponse BunoCs!!
alors je dois utiliser le constructeur public Notification.Builder (Context context, String channelId)


comment je dois initialiser channellId ????
a travers NotificationChannel ??
je suis nouveau en développement android svp me donner l'aide!!
0
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 3 895
15 oct. 2018 à 09:08
0
Joker_ Messages postés 173 Date d'inscription mardi 13 octobre 2009 Statut Membre Dernière intervention 20 janvier 2023 1
16 oct. 2018 à 03:44
Merciiii c'est résolut
0