/** * Initializes a named {@link FirebaseApp} instance using the given options. * * @param options represents the global {@link FirebaseOptions} * @param name unique name for the app. It is an error to initialize an app with an already * existing name. Starting and ending whitespace characters in the name are ignored (trimmed). * @return an instance of {@link FirebaseApp} * @throws IllegalStateException if an app with the same name has already been initialized. */ public static FirebaseApp initializeApp(FirebaseOptions options, String name) { return initializeApp(options, name, DEFAULT_TOKEN_REFRESHER_FACTORY); }
/** * Gets the FirebaseAuth instance for the default {@link FirebaseApp}. * * @return The FirebaseAuth instance for the default {@link FirebaseApp}. */ public static FirebaseAuth getInstance() { return FirebaseAuth.getInstance(FirebaseApp.getInstance()); }
static FirebaseApp initializeApp(FirebaseOptions options, String name, TokenRefresher.Factory tokenRefresherFactory) { FirebaseAppStore appStore = FirebaseAppStore.initialize(); String normalizedName = normalize(name); final FirebaseApp firebaseApp; synchronized (appsLock) { checkState( !instances.containsKey(normalizedName), "FirebaseApp name " + normalizedName + " already exists!"); firebaseApp = new FirebaseApp(normalizedName, options, tokenRefresherFactory); instances.put(normalizedName, firebaseApp); } appStore.persistApp(firebaseApp); return firebaseApp; }
/** * Initializes a named {@link FirebaseApp} instance using Google Application Default Credentials. * Loads additional {@link FirebaseOptions} from the environment in the same way as the * {@link #initializeApp()} method. * * @throws IllegalStateException if an app with the same name has already been initialized. * @throws IllegalArgumentException if an error occurs while loading options from the environment. */ public static FirebaseApp initializeApp(String name) { try { return initializeApp(getOptionsFromEnvironment(), name); } catch (IOException e) { throw new IllegalArgumentException( "Failed to load settings from the system's environment variables", e); } }
/** * Gets the default FirebaseDatabase instance. * * @return A FirebaseDatabase instance. */ public static FirebaseDatabase getInstance() { FirebaseApp instance = FirebaseApp.getInstance(); if (instance == null) { throw new DatabaseException("You must call FirebaseApp.initialize() first."); } return getInstance(instance, instance.getOptions().getDatabaseUrl()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // [START firebase_options] // Manually configure Firebase Options FirebaseOptions options = new FirebaseOptions.Builder() .setApplicationId("1:27992087142:android:ce3b6448250083d1") // Required for Analytics. .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw") // Required for Auth. .setDatabaseUrl("https://myproject.firebaseio.com") // Required for RTDB. .build(); // [END firebase_options] // [START firebase_secondary] // Initialize with secondary app. FirebaseApp.initializeApp(this /* Context */, options, "secondary"); // Retrieve secondary app. FirebaseApp secondary = FirebaseApp.getInstance("secondary"); // Get the database for the other app. FirebaseDatabase secondaryDatabase = FirebaseDatabase.getInstance(secondary); // [END firebase_secondary] } }
public static <T extends FirebaseService> T addService( @NonNull FirebaseApp app, @NonNull T service) { app.addService(service); return service; }
/** * Initializes the default {@link FirebaseApp} instance using the given options. * * @throws IllegalStateException if the default app has already been initialized. */ public static FirebaseApp initializeApp(FirebaseOptions options) { return initializeApp(options, DEFAULT_APP_NAME); }
/** * Returns the default (first initialized) instance of the {@link FirebaseApp}. * * @throws IllegalStateException if the default app was not initialized. */ @Nullable public static FirebaseApp getInstance() { return getInstance(DEFAULT_APP_NAME); }
/** * Initializes the default {@link FirebaseApp} instance using Google Application Default * Credentials. Also attempts to load additional {@link FirebaseOptions} from the environment * by looking up the {@code FIREBASE_CONFIG} environment variable. If the value of * the variable starts with <code>'{'</code>, it is parsed as a JSON object. Otherwise it is * treated as a file name and the JSON content is read from the corresponding file. * * @throws IllegalStateException if the default app has already been initialized. * @throws IllegalArgumentException if an error occurs while loading options from the environment. */ public static FirebaseApp initializeApp() { return initializeApp(DEFAULT_APP_NAME); }
/** * Gets the {@link FirebaseInstanceId} instance for the default {@link FirebaseApp}. * * @return The {@link FirebaseInstanceId} instance for the default {@link FirebaseApp}. */ public static FirebaseInstanceId getInstance() { return getInstance(FirebaseApp.getInstance()); }
@Override public void onCreate() { super.onCreate(); FirebaseApp.initializeApp(this); FirebaseDatabase.getInstance().setPersistenceEnabled(true); } }
/** * Gets the {@link FirebaseMessaging} instance for the default {@link FirebaseApp}. * * @return The {@link FirebaseMessaging} instance for the default {@link FirebaseApp}. */ public static FirebaseMessaging getInstance() { return getInstance(FirebaseApp.getInstance()); }
GoogleFirebaseBackend(boolean isEnabled, String name, String credsPath, String db) { this.isEnabled = isEnabled; if (!isEnabled) { return; } try { FirebaseApp fbApp = FirebaseApp.initializeApp(getOpts(credsPath, db), name); fbAuth = FirebaseAuth.getInstance(fbApp); FirebaseDatabase.getInstance(fbApp); log.info("Google Firebase Authentication is ready"); } catch (IOException e) { throw new RuntimeException("Error when initializing Firebase", e); } }
public static StorageClient getInstance() { return getInstance(FirebaseApp.getInstance()); }
@Override public void onCreate() { super.onCreate(); FirebaseApp.initializeApp(getApplicationContext()); firebaseAuth = GetFirebaseAuth_Instance.getFirebaseAuth_Instance(); databaseReference = GetFirebaseAuth_Instance.getFirebaseDatabase_Instance(); }
private Repo getLocalRepo(Context ctx, RepoInfo info) throws DatabaseException { ctx.freeze(); // No-op if it's already frozen String repoHash = "https://" + info.host + "/" + info.namespace; synchronized (repos) { if (!repos.containsKey(ctx) || !repos.get(ctx).containsKey(repoHash)) { // Calling this should create the repo. InternalHelpers.createDatabaseForTests( FirebaseApp.getInstance(), info, (DatabaseConfig) ctx); } return repos.get(ctx).get(repoHash); } }
public DesktopFirebaseDatabase(String name, FirebaseConfiguration firebaseConfiguration) { FirebaseOptions.Builder builder = new FirebaseOptions.Builder() .setServiceAccount(firebaseConfiguration.serviceAccount.read()) .setDatabaseUrl(firebaseConfiguration.databaseUrl); if (firebaseConfiguration.desktopFirebaseUser != null) { HashMap<String, Object> auth = new HashMap<>(); auth.put("uid", firebaseConfiguration.desktopFirebaseUser.getUid()); builder.setDatabaseAuthVariableOverride(auth); } if (name.equals(GDXFirebase.DEFAULT_APP_NAME)) { app = FirebaseApp.initializeApp(builder.build()); } else { app = FirebaseApp.initializeApp(builder.build(), name); } }
/** * Gets the {@link FirebaseProjectManagement} instance for the default {@link FirebaseApp}. * * @return the {@link FirebaseProjectManagement} instance for the default {@link FirebaseApp} */ @NonNull public static FirebaseProjectManagement getInstance() { return getInstance(FirebaseApp.getInstance()); }
public static void main(String[] args) { // Initialize Firebase try { // [START initialize] FileInputStream serviceAccount = new FileInputStream("service-account.json"); FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(GoogleCredentials.fromStream(serviceAccount)) .setDatabaseUrl(DATABASE_URL) .build(); FirebaseApp.initializeApp(options); // [END initialize] } catch (IOException e) { System.out.println("ERROR: invalid service account credentials. See README."); System.out.println(e.getMessage()); System.exit(1); } // Shared Database reference database = FirebaseDatabase.getInstance().getReference(); // Start listening to the Database startListeners(); // Kick off weekly email task startWeeklyTopPostEmailer(); }