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
|
private void sendNotification(String greetMsg) {
String sMsg = "";
String sNotifMsg = "";
int iTypeNotif=0;
Date now = new Date();
notifyID = now.getTime();
Intent resultIntent = new Intent(this, NotifAcitivity.class);
resultIntent.putExtra("greetjson", greetMsg); // ON PASSE BIEN LE MESSAGE
resultIntent.setAction(String.valueOf(notifyID));
resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), (int) notifyID,
resultIntent, 0);
NotificationCompat.Builder mNotifyBuilder;
NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
JSONObject jsonObj = null;
try {
jsonObj = new JSONObject(greetMsg);
sMsg = jsonObj.getString("msg");
Log.v(Constantes.TAG, "MESSAGE = "+sMsg);
// Récuperer le type de notfif
Log.v(Constantes.TAG, ProcedureGlobale.getParams("TYPE_NOTIF",sMsg)); // ICI J'AI BIEN LE MESSAGE QUI CHANGE
iTypeNotif = Integer.parseInt(ProcedureGlobale.getParams("TYPE_NOTIF",sMsg));
switch (iTypeNotif){
case Constantes.TYPE_MSG:
sNotifMsg = "Vous avez une message d'utilisateur.";
break;
case Constantes.TYPE_TEMPS:
sNotifMsg = "Un de vos compte arrive à terme.";
break;
case Constantes.TYPE_AMENDE:
sNotifMsg = "Vous avez une amende.";
break;
}
} catch (JSONException e) {
e.printStackTrace();
}
mNotifyBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Notification")
.setContentText(sNotifMsg)
.setSmallIcon(R.drawable.ic_launcher);
// Set pending intent
mNotifyBuilder.setContentIntent(resultPendingIntent);
// Set Vibrate, Sound and Light
int defaults = 0;
defaults = defaults | Notification.DEFAULT_LIGHTS;
defaults = defaults | Notification.DEFAULT_VIBRATE;
defaults = defaults | Notification.DEFAULT_SOUND;
defaults = defaults | Notification.FLAG_AUTO_CANCEL;
mNotifyBuilder.setDefaults(defaults);
// Set the content for Notification
mNotifyBuilder.setContentText(sNotifMsg);
// Set autocancel
mNotifyBuilder.setAutoCancel(true);
// Post a notification
mNotificationManager.notify((int)notifyID, mNotifyBuilder.build());
} |
Partager