Java Code Examples for com.google.firebase.FirebaseApp#getInstance()

The following examples show how to use com.google.firebase.FirebaseApp#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirebaseInitProviderNoIdsInResourcesTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void testFirebaseInitProvider() throws Exception {
  ProviderInfo providerInfo = new ProviderInfo();
  providerInfo.authority = "com.google.android.gms.tests.common.firebaseinitprovider";
  firebaseInitProvider.attachInfo(targetContext, providerInfo);
  try {
    FirebaseApp.getInstance();
    fail();
  } catch (Exception expected) {
  }

  // Now we set an app explicitly.
  FirebaseOptions firebaseOptions =
      new FirebaseOptions.Builder()
          .setApiKey(GOOGLE_API_KEY)
          .setApplicationId(GOOGLE_APP_ID)
          .build();
  FirebaseApp firebaseApp = FirebaseApp.initializeApp(targetContext, firebaseOptions);

  assertEquals(firebaseApp, FirebaseApp.getInstance());
}
 
Example 2
Source File: FirebaseInAppMessagingDisplayRegistrar.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
private FirebaseInAppMessagingDisplay buildFirebaseInAppMessagingUI(
    ComponentContainer container) {
  FirebaseApp firebaseApp = FirebaseApp.getInstance();
  FirebaseInAppMessaging headless = container.get(FirebaseInAppMessaging.class);
  Application firebaseApplication = (Application) firebaseApp.getApplicationContext();

  UniversalComponent universalComponent =
      DaggerUniversalComponent.builder()
          .applicationModule(new ApplicationModule(firebaseApplication))
          .build();
  AppComponent instance =
      DaggerAppComponent.builder()
          .universalComponent(universalComponent)
          .headlessInAppMessagingModule(new HeadlessInAppMessagingModule(headless))
          .build();

  FirebaseInAppMessagingDisplay firebaseInAppMessagingDisplay =
      instance.providesFirebaseInAppMessagingUI();
  firebaseApplication.registerActivityLifecycleCallbacks(firebaseInAppMessagingDisplay);
  return firebaseInAppMessagingDisplay;
}
 
Example 3
Source File: FirebaseDatabase.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the default FirebaseDatabase instance.
 *
 * @return A FirebaseDatabase instance.
 */
@NonNull
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());
}
 
Example 4
Source File: TestUtils.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
public static FirebaseApp getAppInstance(Context context) {
    try {
        return FirebaseApp.getInstance(APP_NAME);
    } catch (IllegalStateException e) {
        return initializeApp(context);
    }
}
 
Example 5
Source File: FirebaseUtils.java    From android-rxgeofence with MIT License 5 votes vote down vote up
private static FirebaseApp getApp(String appName) {
  FirebaseApp app;
  try {
    app = FirebaseApp.getInstance(appName);
    return app;
  } catch (Exception e) {
    return null;
  }
}
 
Example 6
Source File: MainActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // [START firebase_options]
    // Manually configure Firebase Options. The following fields are REQUIRED:
    //   - Project ID
    //   - App ID
    //   - API Key
    FirebaseOptions options = new FirebaseOptions.Builder()
            .setProjectId("my-firebase-project")
            .setApplicationId("1:27992087142:android:ce3b6448250083d1")
            .setApiKey("AIzaSyADUe90ULnQDuGShD9W23RDP0xmeDc6Mvw")
            // setDatabaseURL(...)
            // setStorageBucket(...)
            .build();
    // [END firebase_options]

    // [START firebase_secondary]
    // Initialize with secondary app
    FirebaseApp.initializeApp(this /* Context */, options, "secondary");

    // Retrieve secondary FirebaseApp
    FirebaseApp secondary = FirebaseApp.getInstance("secondary");
    // [END firebase_secondary]
}
 
Example 7
Source File: FireBase.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private FireBase() {
    app = FirebaseApp.getInstance();
    auth = FirebaseAuth.getInstance(app);

    /*
    FirebaseDatabase fdb = FirebaseDatabase.getInstance(app);
    fdb.setPersistenceEnabled(true);
    database = fdb.getReference();
    */

}
 
Example 8
Source File: FirestoreArrayTest.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private FirebaseApp getAppInstance(Context context) {
    try {
        return FirebaseApp.getInstance(FIREBASE_APP_NAME);
    } catch (IllegalStateException e) {
        return initializeApp(context);
    }
}
 
Example 9
Source File: AuthOperationManager.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private FirebaseApp getScratchApp(FirebaseApp defaultApp) {
    try {
        return FirebaseApp.getInstance(firebaseAppName);
    } catch (IllegalStateException e) {
        return FirebaseApp.initializeApp(defaultApp.getApplicationContext(),
                defaultApp.getOptions(), firebaseAppName);
    }
}
 
Example 10
Source File: AuthOperationManager.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private FirebaseAuth getScratchAuth(FlowParameters flowParameters) {
    // Use a different FirebaseApp so that the anonymous user state is not lost in our
    // original FirebaseAuth instance.
    if (mScratchAuth == null) {
        FirebaseApp app = FirebaseApp.getInstance(flowParameters.appName);
        mScratchAuth = FirebaseAuth.getInstance(getScratchApp(app));
    }
    return mScratchAuth;
}
 
Example 11
Source File: FirebaseDatabase.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a FirebaseDatabase instance for the specified URL.
 *
 * @param url The URL to the Firebase Database instance you want to access.
 * @return A FirebaseDatabase instance.
 */
@NonNull
public static FirebaseDatabase getInstance(@NonNull String url) {
  FirebaseApp instance = FirebaseApp.getInstance();
  if (instance == null) {
    throw new DatabaseException("You must call FirebaseApp.initialize() first.");
  }
  return getInstance(instance, url);
}
 
Example 12
Source File: IntegrationTestUtil.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
public static FirebaseApp testFirebaseApp() {
  try {
    return FirebaseApp.getInstance(FirebaseApp.DEFAULT_APP_NAME);
  } catch (IllegalStateException e) {
    return FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext(), OPTIONS);
  }
}
 
Example 13
Source File: FirebaseFirestore.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@NonNull
public static FirebaseFirestore getInstance() {
  FirebaseApp app = FirebaseApp.getInstance();
  if (app == null) {
    throw new IllegalStateException("You must call FirebaseApp.initializeApp first.");
  }
  return getInstance(app, DatabaseId.DEFAULT_DATABASE_ID);
}
 
Example 14
Source File: DynamicLink.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/** @hide */
public Builder(FirebaseDynamicLinksImpl firebaseDynamicLinks) {
  firebaseDynamicLinksImpl = firebaseDynamicLinks;
  builderParameters = new Bundle();
  if (FirebaseApp.getInstance() != null) {
    builderParameters.putString(
        KEY_API_KEY, FirebaseApp.getInstance().getOptions().getApiKey());
  }
  fdlParameters = new Bundle();
  builderParameters.putBundle(KEY_DYNAMIC_LINK_PARAMETERS, fdlParameters);
}
 
Example 15
Source File: FirebaseCrashlytics.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the singleton {@link FirebaseCrashlytics} instance.
 *
 * <p>The default {@link FirebaseApp} instance must be initialized before this function is called.
 * See <a
 * href="https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseApp">
 * FirebaseApp</a> for more information.
 */
@NonNull
public static FirebaseCrashlytics getInstance() {
  final FirebaseApp app = FirebaseApp.getInstance();
  final FirebaseCrashlytics instance = app.get(FirebaseCrashlytics.class);
  if (instance == null) {
    throw new NullPointerException("FirebaseCrashlytics component is not present.");
  }
  return instance;
}
 
Example 16
Source File: DecoratorApplication.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 4 votes vote down vote up
public static FirebaseApp getFirebaseApp() {
    return FirebaseApp.getInstance(FIREBASE_NAME);
}
 
Example 17
Source File: FirebaseSegmentation.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@link FirebaseSegmentation} initialized with the default {@link FirebaseApp}.
 *
 * @return a {@link FirebaseSegmentation} instance
 */
@NonNull
public static FirebaseSegmentation getInstance() {
  FirebaseApp defaultFirebaseApp = FirebaseApp.getInstance();
  return getInstance(defaultFirebaseApp);
}
 
Example 18
Source File: IntegrationTestUtils.java    From firebase-admin-java with Apache License 2.0 4 votes vote down vote up
public AppHttpClient() {
  this(FirebaseApp.getInstance());
}
 
Example 19
Source File: AnonymousSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
private FirebaseAuth getAuth() {
    FirebaseApp app = FirebaseApp.getInstance(getArguments().appName);
    return FirebaseAuth.getInstance(app);
}
 
Example 20
Source File: FirebaseInstallations.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the {@link FirebaseInstallations} initialized with the default {@link FirebaseApp}.
 *
 * @return a {@link FirebaseInstallations} instance
 */
@NonNull
public static FirebaseInstallations getInstance() {
  FirebaseApp defaultFirebaseApp = FirebaseApp.getInstance();
  return getInstance(defaultFirebaseApp);
}