Bonjour
Je vous explique mon probleme j'aimerais enfaite recevoir une notification depuis une Firebase quand un de mes seuils n'est plus dans le champ de valeur comprise je m'explique

J'ai plusieurs mesures a rapatrié depuis mon serveur(mpx,rds etc....) qui doivent être tous dans un champ de valeur a ne pas etre dépasser mais si le valeur n'est pas comprise dans mon champ de valeur et ce même si l'application est fermé je veux que une notification depuis n'importe qu'elle application (exemple si je suis sur google depuis mon portable ) me prévienne que le valeur dépasse le champs

Pour ce je me suis intéresser au Firebase depuis google mais se que je ne comprend c'est que depuis une Firebase je ne peux juste envoyer manuellement une alerte (notification) et non automatiquement

Si vous pouviez m'aidez a comprendre comment utilisé une Firebase automatiquement je vous serais reconnaissant et surtout je souhaite vraiment que sa me donne une notification quand l'application n'est pas en cours ou même si elle est en cours ! je vous présente mon code pour que vous compreniez mieux .

recuperationJson.java (je voudrais juste faire pour la valeur mpx pour l'instant)mpxIntMix et mpxIntMax correspond au seuil et mpxInt correspond a la valeur de mpx
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
public class recuperationJson extends AppCompatActivity implements getData.ReturnValue {
    private getData data=null;
    private JSONObject jObj = null;
    private String json_url = "http://192.168.0.14/projet/php/fichier.php";//adresse ip du serveur + chemin
    final private Handler handler = new Handler(); // Handler car une asynctask ne peut pas être eappelé par un autre thread que l'ui
    private Timer timer = new Timer();
    private TextView Mpx, Al, Ar, Rds, Pilots, Frequence, Rf,idsighfox;
   private  int mpxInt, arInt, alInt, rdsInt, pilotsInt, frequenceInt, rfInt,
            mpxIntMin,mpxIntMax,arIntMin,arIntMax,alIntMin,alIntMax,rdsIntMin,rdsIntMax,pilotIntMin,pilotIntMax,frequenceIntMin,frequenceIntMax,rfInMin,rfIntMax;
private String longitude,altitude;
 
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /******************************************************************************************/
        //logo multisys
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.drawable.multi);
        getSupportActionBar().setDisplayShowTitleEnabled(false);
        /******************************************************************************************/
 
    //Instancie getData et l'execute
        data = new getData(json_url);
        data.setReturnListener(this);
        data.execute((Void) null);
    /**********************************************************************************************/
 
    //créer le timer
        timer.schedule(MyTimerTask, 0, 5000/*ms*/);//commence a 0 seconde toutes les 5 seconds
    /**********************************************************************************************/
 
        //Associe les widgets aux variables de la vue main
        idsighfox=(TextView)findViewById(R.id.nomAntenne);
        Mpx = (TextView) findViewById(R.id.mpx);
        Ar = (TextView) findViewById(R.id.ar);
        Al = (TextView) findViewById(R.id.al);
        Rds = (TextView) findViewById(R.id.rds);
        Pilots = (TextView) findViewById(R.id.pilots);
        Frequence = (TextView) findViewById(R.id.frequence);
        Rf = (TextView) findViewById(R.id.rf);
        /**********************************************************************************************/
    }
 
    //Méthode qui renvoie la valeur de getData
    @Override
    public void renvoyerValeurString(String valeurARenvoyer) {
 
        data = null;
        //Ici je récupère directement mon json contenu dans la variable valeurARenvoyer
        try {
            // Json Object {}
            /**************************************************************************************/
            //Insere les valeurs du json dans la classe valeur qui contient les get et set
            String mpxMin,mpxMax,mpx,rdsMin,rdsMax, rds,alMax,alMin, al,arMax,arMin, ar,frequenceMax,frequenceMin, frequence,pilotMax,pilotMin, pilot, id, id_SIGFOX, timestamps,rfMax,rfMin, rf;
            jObj = new JSONObject(valeurARenvoyer);
            mpx = jObj.getString("mpx");//se place a l'endroit MPX du json et obtient le string apres les :
            mpxMin=jObj.getString("mpxMin");
            mpxMax=jObj.getString("mpxMax");
            rds = jObj.getString("rds");
            rdsMin = jObj.getString("rdsMin");
            rdsMax = jObj.getString("rdsMax");
            rf = jObj.getString("rf");
            rfMin = jObj.getString("rfMin");
            rfMax = jObj.getString("rfMax");
            frequence = jObj.getString("frequence");
            frequenceMin = jObj.getString("frequenceMin");
            frequenceMax = jObj.getString("frequenceMax");
            timestamps = jObj.getString("timestamp");
            id = jObj.getString("id");
            id_SIGFOX = jObj.getString("idsighfox");
            pilot = jObj.getString("pilot");
            pilotMin = jObj.getString("pilotMin");
            pilotMax = jObj.getString("pilotMax");
            al = jObj.getString("al");
            alMin = jObj.getString("alMin");
            alMax = jObj.getString("alMax");
            ar = jObj.getString("ar");
            arMin = jObj.getString("arMin");
            arMax = jObj.getString("arMax");
            longitude=jObj.getString("longitude");
            altitude=jObj.getString("altitude");
            /**************************************************************************************/
 
 
            //Valeurs
            Valeur valeurs = new Valeur (mpx,  rds,  al, ar, pilot, frequence,  id, timestamps,  id_SIGFOX,  rf );
 
            //Transforme les valeurs String en Int
            mpxInt = Integer.parseInt(valeurs.getMpx());
            arInt = Integer.parseInt(valeurs.getAr());
            alInt = Integer.parseInt(valeurs.getAl());
            rdsInt = Integer.parseInt(valeurs.getRds());
            rfInt = Integer.parseInt(valeurs.getRf());
            frequenceInt = Integer.parseInt(valeurs.getFrequence());
            pilotsInt = Integer.parseInt(valeurs.getPilots());
            /**************************************************************************************/
 
            //Seuils
            Seuil seuil=new Seuil(mpxMin,mpxMax,rdsMin,rdsMax,alMax,alMin,arMax,arMin,pilotMin,pilotMax,frequenceMin,frequenceMax,rfMin,rfMax);
           //Transforme les valeurs String en Int
            mpxIntMin=Integer.parseInt(seuil.getMpxMin());
            mpxIntMax=Integer.parseInt(seuil.getMpxMax());
 
            arIntMin=Integer.parseInt(seuil.getArMin());
            arIntMax=Integer.parseInt(seuil.getArMax());
 
            alIntMin=Integer.parseInt(seuil.getAlMin());
            alIntMax=Integer.parseInt(seuil.getAlMax());
 
            rdsIntMin=Integer.parseInt(seuil.getRdsMin());
            rdsIntMax=Integer.parseInt(seuil.getRdsMax());
 
            rfInMin=Integer.parseInt(seuil.getRfMin());
            rfIntMax=Integer.parseInt(seuil.getRfMax());
 
            frequenceIntMin=Integer.parseInt(seuil.getFrequenceMin());
            frequenceIntMax=Integer.parseInt(seuil.getFrequenceMax());
 
            pilotIntMin=Integer.parseInt(seuil.getPilotMin());
            pilotIntMax=Integer.parseInt(seuil.getPilotMax());
            /**************************************************************************************/
            idsighfox.setText(valeurs.getId_SIGFOX());
 
            if (mpxInt <mpxIntMin || mpxInt > mpxIntMax ){
 
                Mpx.setText(valeurs.getMpx());//affiche la valeur mpx dans le textView
                Mpx.setTextColor(Color.parseColor("#DF0101"));//red
 
            } else {
 
                Mpx.setText(valeurs.getMpx());
 
            }
MyFirebaseMessagingService .java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
public class MyFirebaseMessagingService extends FirebaseMessagingService {
   // private static final String TAG = "FCM Service";
   /* @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // TODO: Handle FCM messages here.
        // If the application is in the foreground handle both data and notification messages here.
        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated.
        Log.d(TAG, "From: " + remoteMessage.getFrom());
        Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());*/
 
 
   public void onMessageReceived(RemoteMessage remoteMessage) {
        Intent i =new Intent(this,recuperationJson.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
       PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_ONE_SHOT);
 
       NotificationCompat.Builder notificationBuilder=new NotificationCompat.Builder(this);
        notificationBuilder.setContentTitle("FCM NOTIFICATION");
        notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
        notificationBuilder.setAutoCancel(true);
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
        notificationBuilder.setContentIntent(pendingIntent);
        NotificationManager notidicationManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notidicationManager.notify(0,notificationBuilder.build());
 
 
    }
}
MyFirebaseInstanceIdService .java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService {
    private  static final String REG_TOKEN="REG_TOKEN";
    @Override
    public void onTokenRefresh() {
        String recent_token = FirebaseInstanceId.getInstance().getToken();
            Log.d(REG_TOKEN,recent_token);
 
    }
    }