Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyService extends FirebaseMessagingService
- public static final String EXTRA_NOTIFICATION_OBJECT = "com.xxx.yyy.EXTRA_NOTIFICATION_OBJECT";
- public static final String NOTIFICATION_PRIVATE = "com.xxx.yyy.permission.NOTIFICATION";
- @Override
- public void onMessageReceived(RemoteMessage remoteMessage) {
- Intent i = new Intent(ACTION_SHOW_NOTIFICATION);
- i.putExtra(EXTRA_NOTIFICATION_OBJECT, "Hello World!");
- sendOrderedBroadcast(i, NOTIFICATION_PRIVATE, new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (getResultCode() == Activity.RESULT_OK) {
- buildNotification();
- }
- }
- }, null, Activity.RESULT_OK, null, null);
- }
- MainActivity
- BroadcastReceiver mNotificationBroadcastReceiver;
- OnCreate
- mNotificationBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- addCountToBell();
- setResultCode(Activity.RESULT_CANCELED);
- //tell the sender of the broadcast that it received the broadcast
- }
- };
- OnResume
- registerReceiver(mNotificationBroadcastReceiver, filter,
- MyService.NOTIFICATION_PRIVATE, null);
- onPause
- unregisterReceiver(mNotificationBroadcastReceiver);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement