Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public void onMessageReceived(RemoteMessage remoteMessage) {
  2. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
  3. String opcija = sharedPreferences.getString("opcija", null);
  4. if(opcija.contains("1")){
  5. showNotification(remoteMessage.getData().get("poruka"));
  6. } else {
  7. showNotification(remoteMessage.getData().get("poruka"));
  8. }
  9. }
  10.  
  11. private void showNotification(String poruka) {
  12. Intent i = new Intent(this, MainActivity.class);
  13. i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  14.  
  15. PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_UPDATE_CURRENT);
  16. NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
  17. .setAutoCancel(true)
  18. .setContentTitle("Obavijest")
  19. .setContentText(poruka)
  20. .setContentIntent(pendingIntent);
  21. NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  22. manager.notify(0,builder.build());
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement