title: Get shared preference variable in react native
body: <p>I am writing an application in react native(android). I want to save the fcm token in shared preference and want to access this token in react native.How is it possible? Following is my code in android for generating token and saving to shared preference. So how do i access this token in react native.Anybody please help me..</p>
  
  <p><strong>MyInstanceIDListenerService.java</strong></p>
  
  <pre><code>public class MyInstanceIDListenerService extends FirebaseInstanceIdService {
  @Override
  public void onTokenRefresh() {
      String refreshedToken = FirebaseInstanceId.getInstance().getToken();
      Log.d(TAG, "Refreshed token: " + refreshedToken);
      storeToken(refreshedToken);
  }
  private void storeToken(String token) {
      //saving the token on shared preferences
      SharedPrefManager.getInstance(getApplicationContext()).saveDeviceToken(token);
  }
  }
  </code></pre>
  
  <p><strong>SharedPrefManager.java</strong></p>
  
  <pre><code>public class SharedPrefManager {
      private static final String SHARED_PREF_NAME = "FCMSharedPref";
      private static final String TAG_TOKEN = "tagtoken";
  
      private static SharedPrefManager mInstance;
      private static Context mCtx;
  
      private SharedPrefManager(Context context) {
          mCtx = context;
      }
  
      public static synchronized SharedPrefManager getInstance(Context context) {
          if (mInstance == null) {
              mInstance = new SharedPrefManager(context);
          }
          return mInstance;
      }
  
      //this method will save the device token to shared preferences
      public boolean saveDeviceToken(String token){
          SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE);
          SharedPreferences.Editor editor = sharedPreferences.edit();
          editor.putString(TAG_TOKEN, token);
          editor.apply();
          return true;
      }
  }
  </code></pre>