Guest User

Untitled

a guest
Apr 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. package com.developerhouse.push;
  2.  
  3. import com.google.android.gms.gcm.GcmListenerService;
  4.  
  5. import android.app.NotificationManager;
  6. import android.app.PendingIntent;
  7. import android.content.Context;
  8. import android.content.Intent;
  9. import android.media.RingtoneManager;
  10. import android.net.Uri;
  11. import android.os.Bundle;
  12. import android.support.v4.app.NotificationCompat;
  13.  
  14. public class MyGcmListenerService extends GcmListenerService {
  15.  
  16. public static final int MESSAGE_NOTIFICATION_ID = 435345;
  17. private NotificationManager mNotificationManager;
  18.  
  19. @Override
  20. public void onMessageReceived(String from, Bundle data) {
  21. String message = data.getString("message");
  22. createNotification(message);
  23. }
  24.  
  25. // Creates notification based on title and body received
  26. private void createNotification(String body) {
  27. mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  28.  
  29. Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  30. long[] pattern = {500};
  31.  
  32. PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
  33. new Intent(this, MainActivity.class), 0);
  34. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
  35. this).setSmallIcon(R.drawable.notify)
  36. .setContentTitle("UrbanSide PUSH").setVibrate(pattern)
  37. .setStyle(new NotificationCompat.BigTextStyle().bigText(body))
  38. .setContentText(body)
  39. .setAutoCancel(true).setSound(sound);
  40.  
  41. mBuilder.setContentIntent(contentIntent);
  42. mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
  43. }
  44. }
  45.  
  46. Intent intent = new Intent(this, MainActivity.class);
  47. intent.putExtra("body", body);
  48.  
  49. PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
Add Comment
Please, Sign In to add comment