private void storeRegistrationId(Context context, String regId) {
   final SharedPreferences prefs = UserPreferences.getUserPreferences(context);
   int appVersion = getAppVersion(context);
   Log.i("TAG", "Saving regId on app version " + appVersion);
   SharedPreferences.Editor editor = prefs.edit();
   editor.putString(PROPERTY_REG_ID, regId);
   editor.putInt(PROPERTY_APP_VERSION, appVersion);
   editor.commit();
 }
  private static String getRegistrationId(Context context) {
    final SharedPreferences prefs = UserPreferences.getUserPreferences(context);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.isEmpty()) {
      Log.i("TAG", "Registration not found.");
      return "";
    }

    int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int currentVersion = getAppVersion(context);
    if (registeredVersion != currentVersion) {
      Log.i("TAG", "App version changed.");
      return "";
    }
    return registrationId;
  }