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

The following examples show how to use com.google.firebase.FirebaseApp#get() . 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: FirebaseDatabase.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a FirebaseDatabase instance for the specified URL, using the specified FirebaseApp.
 *
 * @param app The FirebaseApp to get a FirebaseDatabase for.
 * @param url The URL to the Firebase Database instance you want to access.
 * @return A FirebaseDatabase instance.
 */
@NonNull
public static synchronized FirebaseDatabase getInstance(
    @NonNull FirebaseApp app, @NonNull String url) {
  if (TextUtils.isEmpty(url)) {
    throw new DatabaseException(
        "Failed to get FirebaseDatabase instance: Specify DatabaseURL within "
            + "FirebaseApp or from your getInstance() call.");
  }

  ParsedUrl parsedUrl = Utilities.parseUrl(url, getEmulatorServiceSettings(app));
  if (!parsedUrl.path.isEmpty()) {
    throw new DatabaseException(
        "Specified Database URL '"
            + url
            + "' is invalid. It should point to the root of a "
            + "Firebase Database but it includes a path: "
            + parsedUrl.path.toString());
  }

  checkNotNull(app, "Provided FirebaseApp must not be null.");
  FirebaseDatabaseComponent component = app.get(FirebaseDatabaseComponent.class);
  checkNotNull(component, "Firebase Database component is not present.");

  return component.get(parsedUrl.repoInfo);
}
 
Example 2
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 3
Source File: FunctionsRegistrarTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void getComponents_publishesLibVersionComponent() {
  FirebaseApp app =
      FirebaseApp.initializeApp(
          RuntimeEnvironment.application.getApplicationContext(),
          new FirebaseOptions.Builder()
              .setApplicationId("1:196403931065:android:60949756fbe381ea")
              .build());

  UserAgentPublisher userAgentPublisher = app.get(UserAgentPublisher.class);
  String actualUserAgent = userAgentPublisher.getUserAgent();

  assertThat(actualUserAgent).contains("fire-fn");
}
 
Example 4
Source File: FirebaseFunctions.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Cloud Functions client with the given app and region.
 *
 * @param app The app for the Firebase project.
 * @param region The region for the HTTPS trigger, such as "us-central1".
 */
@NonNull
public static FirebaseFunctions getInstance(@NonNull FirebaseApp app, @NonNull String region) {
  Preconditions.checkNotNull(app, "You must call FirebaseApp.initializeApp first.");
  Preconditions.checkNotNull(region);

  FunctionsMultiResourceComponent component = app.get(FunctionsMultiResourceComponent.class);
  Preconditions.checkNotNull(component, "Functions component does not exist.");

  return component.get(region);
}
 
Example 5
Source File: DatabaseRegistrarTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void getComponents_publishesLibVersionComponent() {
  FirebaseApp app = appForDatabaseUrl(TEST_NAMESPACE, "test");
  UserAgentPublisher userAgentPublisher = app.get(UserAgentPublisher.class);

  String actualUserAgent = userAgentPublisher.getUserAgent();
  assertThat(actualUserAgent).contains("fire-rtdb");
}
 
Example 6
Source File: FirestoreRegistrarTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Ignore
@Test
public void storageRegistrar_getComponents_publishesLibVersionComponent() {
  FirebaseApp app =
      FirebaseApp.initializeApp(
          ApplicationProvider.getApplicationContext(),
          new FirebaseOptions.Builder()
              .setProjectId("projectId")
              .setApplicationId("1:196403931065:android:60949756fbe381ea")
              .build());
  UserAgentPublisher userAgentPublisher = app.get(UserAgentPublisher.class);
  String actualUserAgent = userAgentPublisher.getUserAgent();

  assertThat(actualUserAgent).contains("fire-fst");
}
 
Example 7
Source File: FirebaseFirestore.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@NonNull
private static FirebaseFirestore getInstance(@NonNull FirebaseApp app, @NonNull String database) {
  checkNotNull(app, "Provided FirebaseApp must not be null.");
  FirestoreMultiDbComponent component = app.get(FirestoreMultiDbComponent.class);
  checkNotNull(component, "Firestore component is not present.");
  return component.get(database);
}
 
Example 8
Source File: StorageRegistrarTest.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void getComponents_publishesLibVersionComponent() {
  FirebaseApp app =
      FirebaseApp.initializeApp(
          RuntimeEnvironment.application.getApplicationContext(),
          new FirebaseOptions.Builder()
              .setApplicationId("1:196403931065:android:60949756fbe381ea")
              .build());
  UserAgentPublisher userAgentPublisher = app.get(UserAgentPublisher.class);
  String actualUserAgent = userAgentPublisher.getUserAgent();

  assertThat(actualUserAgent).contains("fire-gcs");
}
 
Example 9
Source File: FirebaseStorage.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
private static FirebaseStorage getInstanceImpl(@NonNull FirebaseApp app, @Nullable Uri url) {
  String bucketName = url != null ? url.getHost() : null;

  if (url != null && !TextUtils.isEmpty(url.getPath())) {
    throw new IllegalArgumentException(STORAGE_BUCKET_WITH_PATH_EXCEPTION);
  }

  Preconditions.checkNotNull(app, "Provided FirebaseApp must not be null.");
  FirebaseStorageComponent component = app.get(FirebaseStorageComponent.class);
  Preconditions.checkNotNull(component, "Firebase Storage component is not present.");
  return component.get(bucketName);
}
 
Example 10
Source File: FirebaseUseExplicitDependenciesPositiveCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/** method returns void so it is not allowed. */
public static void getInstance(FirebaseApp app, String foo) {
  // BUG: Diagnostic contains: FirebaseApp#get(Class) is discouraged
  app.get(String.class);
}
 
Example 11
Source File: FirebaseUseExplicitDependenciesPositiveCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/** method returns String so it is not allowed. */
public static String getInstance(FirebaseApp app) {
  // BUG: Diagnostic contains: FirebaseApp#get(Class) is discouraged
  app.get(String.class);
  return "";
}
 
Example 12
Source File: FirebaseUseExplicitDependenciesNegativeCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/** Valid use with one app parameter. */
public static FirebaseUseExplicitDependenciesNegativeCases getInstance(FirebaseApp app) {
  app.get(String.class);
  return null;
}
 
Example 13
Source File: FirebaseUseExplicitDependenciesNegativeCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/** Valid use with multiple parameters. */
public static FirebaseUseExplicitDependenciesNegativeCases getInstance(
    FirebaseApp app, String foo) {
  app.get(String.class);
  return null;
}
 
Example 14
Source File: FirebaseUseExplicitDependenciesNegativeCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
/** Valid private use with multiple parameters. */
private static FirebaseUseExplicitDependenciesNegativeCases getInstance(
    FirebaseApp app, Integer i) {
  app.get(String.class);
  return null;
}
 
Example 15
Source File: FirebaseUseExplicitDependenciesNegativeCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
public static SuperType getInstance(FirebaseApp app) {
  app.get(String.class);
  return null;
}
 
Example 16
Source File: FirebaseUseExplicitDependenciesNegativeCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
public static Iface getInstance(FirebaseApp app) {
  app.get(String.class);
  return null;
}
 
Example 17
Source File: FirebaseUseExplicitDependenciesPositiveCases.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
public void useOfAppGetInInstanceMethod(FirebaseApp app) {
  // BUG: Diagnostic contains: FirebaseApp#get(Class) is discouraged
  app.get(String.class);
}
 
Example 18
Source File: FirebaseDynamicLinks.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
@NonNull
public static synchronized FirebaseDynamicLinks getInstance(@NonNull FirebaseApp firebaseApp) {
  return firebaseApp.get(FirebaseDynamicLinks.class);
}
 
Example 19
Source File: FirebaseSegmentation.java    From firebase-android-sdk with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the {@link FirebaseSegmentation} initialized with a custom {@link FirebaseApp}.
 *
 * @param app a custom {@link FirebaseApp}
 * @return a {@link FirebaseSegmentation} instance
 */
@NonNull
public static FirebaseSegmentation getInstance(@NonNull FirebaseApp app) {
  Preconditions.checkArgument(app != null, "Null is not a valid value " + "of FirebaseApp.");
  return app.get(FirebaseSegmentation.class);
}
 
Example 20
Source File: FirebaseInstallations.java    From firebase-android-sdk with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the {@link FirebaseInstallations} initialized with a custom {@link FirebaseApp}.
 *
 * @param app a custom {@link FirebaseApp}
 * @return a {@link FirebaseInstallations} instance
 */
@NonNull
public static FirebaseInstallations getInstance(@NonNull FirebaseApp app) {
  Preconditions.checkArgument(app != null, "Null is not a valid value of FirebaseApp.");
  return (FirebaseInstallations) app.get(FirebaseInstallationsApi.class);
}