@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.subscribe: FirebaseMessaging.getInstance().subscribeToTopic("pushNotifications"); Toast.makeText(MainActivity.this, "Subscribed to Topic: Push Notifications", Toast.LENGTH_SHORT).show(); break; case R.id.unsubscribe: FirebaseMessaging.getInstance().unsubscribeFromTopic("pushNotifications"); Toast.makeText(MainActivity.this, "Unsubscribed to Topic: Push Notifications", Toast.LENGTH_SHORT).show(); break; case R.id.sign_out_menu: AuthUI.getInstance().signOut(this); break; default: return super.onOptionsItemSelected(item); } return true;}
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_server_status); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.gold)); setSupportActionBar(toolbar); findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.BROWSER_FORUMS_URL)); startActivity(browserIntent); } }); content = (ViewGroup) findViewById(R.id.content); sharedPref = getSharedPreferences( getString(R.string.preference_file_key), Context.MODE_PRIVATE); FirebaseMessaging.getInstance().subscribeToTopic("server-status"); }
private void handlings(String type, View view) { if (! bloodType.equals(type)) { clearButtons(); view.setBackgroundColor(getResources().getColor(R.color.button_selected)); saveInfo(type); getInfo(); unsubscribe(); FirebaseMessaging.getInstance().subscribeToTopic("blood-" + type); } else if(bloodType.equals(type)) { clearButtons(); unsubscribe(); saveInfo(""); bloodType = ""; } }
@Override public void onCreate() { OneSheeldSdk.init(this); context = getApplicationContext(); setAppPreferences(getSharedPreferences(APP_PREF_NAME, MODE_PRIVATE)); appFont = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf"); parseSocialKeys(); initTaskerPins(); isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)); if (isDebuggable() && !FirebaseApp.getApps(this).isEmpty()) FirebaseMessaging.getInstance().subscribeToTopic("dev"); OneSheeldSdk.setDebugging(isDebuggable); connectionTime = 0; AppShields.getInstance().init(getRememberedShields()); initCrashlyticsAndUncaughtThreadHandler(); super.onCreate(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); viewPager = (ViewPager) findViewById(R.id.viewpager); setupViewPager(viewPager); viewPager.setOffscreenPageLimit(ITEM_COUNT); tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(viewPager); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) { FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL); } else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) { // new push notification is received } } }; }
public void signOut() { view.showProgress(R.string.signing_out); signOutSubscriber = new DefaultSubscriber<String>(view) { @Override public void onNext(String userId) { super.onNext(userId); view.hideProgress(); view.navigateToSplash(); FirebaseMessaging.getInstance().unsubscribeFromTopic("user_" + userId); } @Override public void onError(Throwable e) { super.onError(e); view.showMessage(R.string.sign_out_error); view.hideProgress(); } }; authManager.signOut(signOutSubscriber); }
public void signInWithGoogle(GoogleSignInAccount googleSignInAccount) { signInSubscriber = new DefaultSubscriber<String>(view) { @Override public void onNext(String userId) { super.onNext(userId); view.navigateToUsers(); view.hideProgress(); FirebaseMessaging.getInstance().subscribeToTopic("user_" + userId); } @Override public void onError(Throwable e) { super.onError(e); view.showMessage(R.string.authentication_failed); view.hideProgress(); } }; authManager.signInGoogle(googleSignInAccount, signInSubscriber, createUser); }
private void signOut() { mAuth.signOut(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putString("ustype", "0").apply(); editor.putString("usadmin", "0").apply(); editor.putString("usico", "0").apply(); editor.putString("usosc", "0").apply(); editor.putString("usatw", "0").apply(); editor.putString("usuid", "0").apply(); editor.commit(); String approvetopic = "approve" + userico; String mytopic = "mytopic" + myuserid; FirebaseMessaging.getInstance().unsubscribeFromTopic(mytopic); FirebaseMessaging.getInstance().unsubscribeFromTopic(approvetopic); updateUI(null); }
@Override public void onCreate() { super.onCreate(); MultiDex.install(this); // Logging if (BuildConfig.DEBUG) { Jot.add(new Jot.DebugLogger()); } else { Jot.add(new CrashlyticsLogger()); } // Fabric Fabric.with(this, new Crashlytics(), new Answers()); Analytics.add(AnswersLogger.getInstance()); // Crashlytics Crashlytics.setString("GIT_SHA", BuildConfig.GIT_SHA); Crashlytics.setString("BUILD_TIME", BuildConfig.BUILD_TIME); FirebaseMessaging.getInstance().subscribeToTopic("main-" + BuildConfig.FLAVOR); }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { String keyReceiveNotification = StripSharedPreferencesDataSource.KEY_RECEIVE_NOTIFICATION; if (key.compareTo(keyReceiveNotification) == 0) { boolean receiveNotification = sharedPreferences.getBoolean(keyReceiveNotification, true); FirebaseApp.initializeApp(getActivity().getApplicationContext()); if (receiveNotification) { FirebaseMessaging.getInstance().subscribeToTopic(Configuration.TOPIC_NAME); } else { FirebaseMessaging.getInstance().unsubscribeFromTopic(Configuration.TOPIC_NAME); } } }
@Override public void onSlideChanged(@Nullable Fragment oldFragment, @Nullable Fragment newFragment) { super.onSlideChanged(oldFragment, newFragment); currentSlide++; if (currentSlide.equals(totalSlides)) { if (!getTaskFragment().isJobFinished()) { setSwipeLock(true); setNextPageSwipeLock(false); } // Ask Firebase to register the device in the topic. Used for receiving notification. FirebaseApp.initializeApp(getApplicationContext()); FirebaseMessaging.getInstance().subscribeToTopic(Configuration.TOPIC_NAME); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activity_main); FirebaseMessaging.getInstance().subscribeToTopic("test"); FirebaseInstanceId.getInstance().getToken(); AM = this; loadFirebase(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getSupportActionBar().setElevation(0); } setTitle("All Events"); viewPager = (ViewPager) findViewById(R.id.viewPager); //setRetainInstance(true); viewPager.setOffscreenPageLimit(4); setAdapterfn(); }
public static void onSettingsChange(SharedPreferences sharedPreferences, Resources resources, String key) { switch (key) { case NOTIFICATIONS_NEWS: unsubscribeFromAllNews(resources); String news = sharedPreferences.getString(NOTIFICATIONS_NEWS, "none"); if (news.equals("none")) { break; } String topic = "news-" + news; FirebaseMessaging.getInstance().subscribeToTopic(topic); if (BuildConfig.DEBUG) { FirebaseMessaging.getInstance().subscribeToTopic(topic + "-debug"); } break; case NOTIFICATIONS_PATCH: checkAndUpdatePatchTopic(sharedPreferences, resources); break; } }
public static void checkAndUpdatePatchTopic(SharedPreferences sharedPreferences, Resources resources) { boolean subscribed = sharedPreferences.getBoolean(NOTIFICATIONS_PATCH, true); String intendedTopic = "patch-" + BuildConfig.CARD_DATA_VERSION; String key = resources.getString(R.string.pref_patch_notifications_topic_key); String topic = sharedPreferences.getString(key, null); if (subscribed) { if (!intendedTopic.equals(topic)) { if (topic != null) { FirebaseMessaging.getInstance().unsubscribeFromTopic(topic); } FirebaseMessaging.getInstance().subscribeToTopic(intendedTopic); sharedPreferences.edit().putString(key, intendedTopic).apply(); } } else { if (topic != null) { FirebaseMessaging.getInstance().unsubscribeFromTopic(topic); sharedPreferences.edit().remove(key).apply(); } } }
@Override public void onCreate() { OneSheeldSdk.init(this); context = getApplicationContext(); setAppPreferences(getSharedPreferences(APP_PREF_NAME, MODE_PRIVATE)); appFont = Typeface.createFromAsset(getAssets(), "Roboto-Light.ttf"); parseSocialKeys(); initTaskerPins(); isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)); if (isDebuggable() && !FirebaseApp.getApps(this).isEmpty()) FirebaseMessaging.getInstance().subscribeToTopic("dev"); OneSheeldSdk.setDebugging(isDebuggable); connectionTime = 0; AppShields.getInstance().init(getRememberedShields()); initCrashlyticsAndUncaughtThreadHandler(); detectIfLocatedInTheUs(); super.onCreate(); }
private void switchTopicSubscription(String topic) { FirebaseMessaging.getInstance().subscribeToTopic(topic); LogHelper.d(TAG, "Subscribed to " + topic); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("notifications_department_" + topic, true); for (String departmentKey : departmentKeys) { if (departmentKey.equals(topic)) { continue; } FirebaseMessaging.getInstance().unsubscribeFromTopic(departmentKey); LogHelper.d(TAG, "Unsubscribed from " + departmentKey); editor.putBoolean("notifications_department_" + departmentKey, false); } editor.apply(); }
private void switchTopicSubscription(String topic) { String key = "notifications_" + topic; SharedPreferences.Editor editor; if (sharedPreferences.getBoolean(key, false)) { FirebaseMessaging.getInstance().unsubscribeFromTopic(topic); LogHelper.d(TAG, "Unsubscribed from " + topic); editor = sharedPreferences.edit(); editor.putBoolean(key, false); } else { FirebaseMessaging.getInstance().subscribeToTopic(topic); LogHelper.d(TAG, "Subscribed to " + topic); editor = sharedPreferences.edit(); editor.putBoolean(key, true); } editor.apply(); }
public static void subscribeTopics(boolean isConfMessageCardsEnabled, boolean isRegisteredAttendee) { try { FirebaseMessaging pubSub = FirebaseMessaging.getInstance(); if (isConfMessageCardsEnabled) { if (isRegisteredAttendee) { pubSub.unsubscribeFromTopic(CONFERENCE_MESSAGES_TOPIC_OFFSITE); pubSub.subscribeToTopic(CONFERENCE_MESSAGES_TOPIC_ONSITE); } else { pubSub.subscribeToTopic(CONFERENCE_MESSAGES_TOPIC_OFFSITE); pubSub.unsubscribeFromTopic(CONFERENCE_MESSAGES_TOPIC_ONSITE); } } else { pubSub.unsubscribeFromTopic(CONFERENCE_MESSAGES_TOPIC_ONSITE); pubSub.unsubscribeFromTopic(CONFERENCE_MESSAGES_TOPIC_OFFSITE); } } catch (Throwable throwable) { // Just in case. LOGE(TAG, "Exception updating conference message cards subscription.", throwable); } }
/** * The Application's current Instance ID token is no longer valid and thus a new one must be requested. */ @Override public void onTokenRefresh() { // If you need to handle the generation of a token, initially or after a refresh this is // where you should do that. String token = FirebaseInstanceId.getInstance().getToken(); Log.d(TAG, "FCM Token: " + token); // Once a token is generated, we subscribe to topic. FirebaseMessaging.getInstance().subscribeToTopic(FRIENDLY_ENGAGE_TOPIC); }
public void sendMessage (final String data) { FirebaseMessaging fm = FirebaseMessaging.getInstance(); String token = FirebaseInstanceId.getInstance().getToken(); String msgID = DigestUtils.sha1Hex(token + System.currentTimeMillis()); String SENDER_ID = "someID"; RemoteMessage.Builder RMBuilder = new RemoteMessage.Builder(SENDER_ID + "@gcm.googleapis.com"); RMBuilder.setMessageId(msgID); Map<String, Object> mapData = Utils.jsonToMap(data); for (Map.Entry<String, Object> entry : mapData.entrySet()) { RMBuilder.addData(entry.getKey(), entry.getValue().toString()); } fm.send(RMBuilder.build()); }
@Override public void onTokenRefresh() { // If you need to handle the generation of a token, initially or // after a refresh this is where you should do that. String token = FirebaseInstanceId.getInstance().getToken(); Log.d(TAG, "FCM Token: " + token); // Once a token is generated, we subscribe to topic. FirebaseMessaging.getInstance() .subscribeToTopic(FRIENDLY_ENGAGE_TOPIC); }
@Override public void onCreate() { super.onCreate(); Fabric.with(this, new Crashlytics()); setFirebaseEnabled(false); FirebaseMessaging.getInstance().subscribeToTopic("main"); }
public void subscribe(final CallbackContext callbackContext, final String topic) { mFirebase.cordova.getThreadPool().execute(new Runnable() { public void run() { try { Log.i(TAG, "Subscribing to topic " + topic); FirebaseMessaging.getInstance().subscribeToTopic(topic); callbackContext.success(); } catch (Exception e) { Log.e(TAG, "Error subscribing to topic " + topic); callbackContext.error(e.getMessage()); } } }); }
public void unsubscribe(final CallbackContext callbackContext, final String topic) { mFirebase.cordova.getThreadPool().execute(new Runnable() { public void run() { try { Log.i(TAG, "Unsubscribing from topic " + topic); FirebaseMessaging.getInstance().unsubscribeFromTopic(topic); callbackContext.success(); } catch (Exception e) { Log.e(TAG, "Error unsubscribing from topic " + topic); callbackContext.error(e.getMessage()); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_layout); // suscirpcion a los temas de mensajeria. para una aplicación concreta solo recibiremos notificaciones // de los temas a los que estemos suscritos. FirebaseMessaging.getInstance().subscribeToTopic("test_mensajeria"); }
private void unsubscribe() { FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-Ap"); FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-Bp"); FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-ABp"); FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-Op"); FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-An"); FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-Bn"); FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-ABn"); FirebaseMessaging.getInstance().unsubscribeFromTopic("blood-On"); }
/** * The Application's current Instance ID token is no longer valid and thus a new one must be requested. */ @Override public void onTokenRefresh() { // If you need to handle the generation of a token, initially or after a refresh this is // where you should do that. String token = FirebaseInstanceId.getInstance().getToken(); // Once a token is generated, we subscribe to topic. FirebaseMessaging.getInstance().subscribeToTopic(FRIENDLY_ENGAGE_TOPIC); }
private void subscribeToPushService() { FirebaseMessaging.getInstance().subscribeToTopic("news"); Log.d("AndroidBash", "Subscribed"); //Toast.makeText(MainActivity.this, "Subscribed", Toast.LENGTH_SHORT).show(); String token = FirebaseInstanceId.getInstance().getToken(); // Log and toast Log.d("AndroidBash", token); //Toast.makeText(MainActivity.this, token, Toast.LENGTH_SHORT).show(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification); txtRegId = (EditText) findViewById(R.id.txt_reg_id); txtMessage = (TextView) findViewById(R.id.txt_push_message); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // checking for type intent filter if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) { // gcm successfully registered // now subscribe to `global` topic to receive app wide notifications FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL); displayFirebaseRegId(); } else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) { // new push notification is received String message = intent.getStringExtra("message"); Toast.makeText(getApplicationContext(), "Push notification: " + message, Toast.LENGTH_LONG).show(); txtMessage.setText(message); } } }; displayFirebaseRegId(); }
public void reloadFCMsubscriptions() { FirebaseMessaging fcm = FirebaseMessaging.getInstance(); SharedPreferences sharedPref = getSharedPreferences("notifsettings", MODE_PRIVATE); Set<String> linePref = sharedPref.getStringSet("pref_notifs_lines", null); if (linePref != null && linePref.size() != 0) { fcm.subscribeToTopic("disturbances"); if (BuildConfig.DEBUG) { fcm.subscribeToTopic("disturbances-debug"); } } else { fcm.unsubscribeFromTopic("disturbances"); fcm.unsubscribeFromTopic("disturbances-debug"); } Set<String> sourcePref = sharedPref.getStringSet("pref_notifs_announcement_sources", null); for (Announcement.Source possibleSource : Announcement.getSources()) { if (sourcePref != null && sourcePref.contains(possibleSource.id)) { fcm.subscribeToTopic("announcements-" + possibleSource.id); if (BuildConfig.DEBUG) { fcm.subscribeToTopic("announcements-debug-" + possibleSource.id); } } else { fcm.unsubscribeFromTopic("announcements-" + possibleSource.id); fcm.unsubscribeFromTopic("announcements-debug-" + possibleSource.id); } } }
@Override protected String doInBackground(Void... params) { try { return FirebaseInstanceId.getInstance().getToken(context.getString(R.string.gcm_defaultSenderId), FirebaseMessaging.INSTANCE_ID_SCOPE); } catch (IOException e) { e.printStackTrace(); return null; } }
@Override public void onComplicationActivated(int complicationId, int type, ComplicationManager manager) { // register FCM topic FirebaseMessaging.getInstance().subscribeToTopic("v1"); if (BuildConfig.DEBUG) { FirebaseMessaging.getInstance().subscribeToTopic("debug"); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // init google services GoogleApiAvailability.getInstance().makeGooglePlayServicesAvailable(this); FirebaseMessaging.getInstance().subscribeToTopic("v1"); if (BuildConfig.DEBUG) { FirebaseMessaging.getInstance().subscribeToTopic("debug"); } // bind views statsView = findViewById(R.id.stats); historyView = findViewById(R.id.card_history); historyView.setOnRetryListener(this::onRetryHistory); // get viewmodel viewModel = ViewModelProviders.of(this).get(MainViewModel.class); // TODO get rid of this line? viewModel.init(this); viewModel.observeData(this, this::onHistoryUpdated); viewModel.loadHistory(); // bind ticker Ticker.with(this).bind(this::onTick); // load stats getSupportLoaderManager().initLoader(0, null, this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); intentDetails = (TextView) findViewById(R.id.intentDetails); // String token = FirebaseInstanceId.getInstance().getToken(); FirebaseMessaging.getInstance().subscribeToTopic("fcm_testing"); showIntentDetails(); }
void goToActivity(String userType) { if (userType.equals("1")) { startActivity(new Intent(LoginActivity.this, MainNavigation.class)); Config.TOPIC_GLOBAL = "student"; FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL); } else if (userType.equals("0")) { startActivity(new Intent(LoginActivity.this, TeacherNavigation.class)); Config.TOPIC_GLOBAL = "teacher"; FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL); } }
@Override public void onCreate() { super.onCreate(); CalligraphyConfig.initDefault( new CalligraphyConfig.Builder().setDefaultFontPath("minyna.ttf").setFontAttrId(R.attr.fontPath) .build()); AndroidThreeTen.init(this); FirebaseApp.initializeApp(this); FirebaseMessaging.getInstance().subscribeToTopic("Power_Notifications"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_starting); //Push Notification Common Subscription Topic FirebaseMessaging.getInstance().subscribeToTopic("news"); }
@ReactMethod public void send(String senderId, ReadableMap payload) throws Exception { FirebaseMessaging fm = FirebaseMessaging.getInstance(); RemoteMessage.Builder message = new RemoteMessage.Builder(senderId + "@gcm.googleapis.com") .setMessageId(UUID.randomUUID().toString()); ReadableMapKeySetIterator iterator = payload.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); String value = getStringFromReadableMap(payload, key); message.addData(key, value); } fm.send(message.build()); }
@Override public void onCreate() { super.onCreate(); initRealm(); initializeInjector(); initializeLeakDetection(); networkManager.start(); if (authManager.isSignedIn()) { FirebaseMessaging.getInstance().subscribeToTopic("user_" + authManager.getCurrentUserId()); } }
@Override public void onTerminate() { super.onTerminate(); networkManager.stop(); if (authManager.isSignedIn()) { FirebaseMessaging.getInstance().unsubscribeFromTopic("user_" + authManager.getCurrentUserId()); } }