title: Sending notifications only when user enables it
body: <p>I have a ToggleButton in my app, where users can turn the notifications ON nad OFF. I managed to create a class, where the state of the button is saved, so even after closing the app, the last selected state is showing:</p>
  
  <pre><code>public class SetFragment extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View view =  inflater.inflate(R.layout.fragment_set, container, false);
  
      ToggleButton toggle = view.findViewById(R.id.simpleSwitch);
      toggle.setChecked(readState());
  
  
      toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              if (isChecked) {
                  Log.e("aaaaa","checked");
                  // The toggle is enabled
              } else {
                  Log.e("aaaaa","not checked");
                  // The toggle is disabled
              }
              saveState(isChecked);
          }
      });
  
  
  
      return view;
  }
  
  
  private void saveState(boolean isFavourite) {
      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
      sharedPreferences.edit().putBoolean("State", isFavourite).apply();
  }
  private boolean readState() {
      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
      return sharedPreferences.getBoolean("State", true);
  }
  }
  </code></pre>
  
  <p>Now the problem is, how to send notifications only to those users, who has this option enabled in the app? Now I can send the notifications to all users.</p>
  
  <p>I think if check the <code>readState</code> in my <code>MyFirebaseMessagingServiceclass</code>, and if it is true then do <code>sendNotification</code> otherwise do nothing.</p>
  
  <p>Am I thinking the right way?</p>