Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. dependencies {
  2. compile fileTree(include: ['*.jar'], dir: 'libs')
  3. androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
  4. exclude group: 'com.android.support', module: 'support-annotations'
  5. })
  6. compile 'com.android.support:appcompat-v7:24.2.1'
  7. compile 'com.android.support:design:24.2.1'
  8. testCompile 'junit:junit:4.12'
  9. compile 'com.afollestad.material-dialogs:core:0.9.1.0'
  10. compile 'com.android.support:cardview-v7:21.0.+'
  11. compile 'com.android.support:recyclerview-v7:21.0.+'
  12.  
  13. compile 'com.google.firebase:firebase-messaging:9.4.0'
  14. compile 'com.google.firebase:firebase-auth:9.4.0'
  15.  
  16. compile 'com.google.android.gms:play-services-auth:9.0.0'
  17.  
  18. compile 'com.github.bumptech.glide:glide:3.5.2'
  19.  
  20. compile 'com.google.code.gson:gson:2.6.2'
  21. compile 'com.squareup.retrofit2:retrofit:2.1.0'
  22. compile 'com.squareup.retrofit2:converter-gson:2.1.0'
  23. }
  24.  
  25. public class MyInstanceIDService extends FirebaseInstanceIdService {
  26.  
  27. private static final String TAG = MyInstanceIDService.class.getSimpleName();
  28.  
  29. @Override
  30. public void onTokenRefresh() {
  31. // Get updated InstanceID token.
  32. String refreshedToken = FirebaseInstanceId.getInstance().getToken();
  33. Log.i(TAG, "Token: " + refreshedToken);
  34.  
  35. // If you want to send messages to this application instance or
  36. // manage this apps subscriptions on the server side, send the
  37. // Instance ID token to your app server.
  38. sendRegistrationToServer(refreshedToken);
  39. }
  40. private void sendRegistrationToServer(String token) {
  41. // TODO: Send any registration to your app's servers.
  42. }
  43. }
  44.  
  45. public class MyFirebaseMessagingService extends FirebaseMessagingService {
  46.  
  47. private static final String TAG = MyFirebaseMessagingService.class.getSimpleName();
  48.  
  49. @Override
  50. public void onMessageReceived(RemoteMessage remoteMessage) {
  51. // Create and show notification
  52. sendNotification(remoteMessage.getNotification().getBody());
  53. }
  54.  
  55. private void sendNotification(String messageBody) {
  56. Intent intent = new Intent(this, SplashActivity.class);
  57. intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  58. PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
  59. PendingIntent.FLAG_ONE_SHOT);
  60.  
  61. Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  62. NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
  63. .setSmallIcon(R.drawable.ic_arrow_back_white_24dp)
  64. .setContentTitle("FCM Message")
  65. .setContentText(messageBody)
  66. .setAutoCancel(true)
  67. .setSound(defaultSoundUri)
  68. .setContentIntent(pendingIntent);
  69.  
  70. NotificationManager notificationManager =
  71. (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  72.  
  73. notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement