Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mRegistrationBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
- FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
- displayFirebaseRegId();
- } else if (intent.getAction().equals(Config.PUSH_NOTIFICATION))
- {
- String message = intent.getStringExtra("message");
- Toast.makeText(getApplicationContext(), "Push notification: " + message, Toast.LENGTH_LONG).show();
- txtMessage.setText(message);
- }
- }
- };
- displayFirebaseRegId();
- }
- private void displayFirebaseRegId() {
- SharedPreferences pref = getApplicationContext().getSharedPreferences(Config.SHARED_PREF, 0);
- String regId = pref.getString("regId", null);
- Log.e(TAG, "Firebase reg id: " + regId);
- if (!TextUtils.isEmpty(regId))
- txtRegId.setText("Firebase Reg Id: " + regId);
- else
- txtRegId.setText("Firebase Reg Id is not received yet!");
- }
- @Override
- protected void onResume() {
- super.onResume();
- LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
- new IntentFilter(Config.REGISTRATION_COMPLETE));
- LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
- new IntentFilter(Config.PUSH_NOTIFICATION));
- NotificationUtils.clearNotifications(getApplicationContext());
- }
- @Override
- protected void onPause() {
- LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
- super.onPause();
- }
- compile 'com.google.firebase:firebase-messaging:11.0.4'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement