Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. MyService extends FirebaseMessagingService
  2.  
  3. public static final String EXTRA_NOTIFICATION_OBJECT = "com.xxx.yyy.EXTRA_NOTIFICATION_OBJECT";
  4. public static final String NOTIFICATION_PRIVATE = "com.xxx.yyy.permission.NOTIFICATION";
  5.  
  6. @Override
  7. public void onMessageReceived(RemoteMessage remoteMessage) {
  8. Intent i = new Intent(ACTION_SHOW_NOTIFICATION);
  9. i.putExtra(EXTRA_NOTIFICATION_OBJECT, "Hello World!");
  10. sendOrderedBroadcast(i, NOTIFICATION_PRIVATE, new BroadcastReceiver() {
  11. @Override
  12. public void onReceive(Context context, Intent intent) {
  13. if (getResultCode() == Activity.RESULT_OK) {
  14. buildNotification();
  15. }
  16. }
  17. }, null, Activity.RESULT_OK, null, null);
  18. }
  19.  
  20. MainActivity
  21.  
  22. BroadcastReceiver mNotificationBroadcastReceiver;
  23.  
  24. OnCreate
  25. mNotificationBroadcastReceiver = new BroadcastReceiver() {
  26. @Override
  27. public void onReceive(Context context, Intent intent) {
  28. addCountToBell();
  29. setResultCode(Activity.RESULT_CANCELED);
  30. //tell the sender of the broadcast that it received the broadcast
  31. }
  32. };
  33.  
  34. OnResume
  35. registerReceiver(mNotificationBroadcastReceiver, filter,
  36. MyService.NOTIFICATION_PRIVATE, null);
  37.  
  38. onPause
  39. unregisterReceiver(mNotificationBroadcastReceiver);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement