当前位置: 首页>>代码示例>>Java>>正文


Java FirebaseApp.initializeApp方法代码示例

本文整理汇总了Java中com.google.firebase.FirebaseApp.initializeApp方法的典型用法代码示例。如果您正苦于以下问题:Java FirebaseApp.initializeApp方法的具体用法?Java FirebaseApp.initializeApp怎么用?Java FirebaseApp.initializeApp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.firebase.FirebaseApp的用法示例。


在下文中一共展示了FirebaseApp.initializeApp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testVerifyIdTokenWithExplicitProjectId

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Test
public void testVerifyIdTokenWithExplicitProjectId() throws Exception {
  GoogleCredentials credentials = TestOnlyImplFirebaseTrampolines.getCredentials(firebaseOptions);
  Assume.assumeFalse(
      "Skipping testVerifyIdTokenWithExplicitProjectId for service account credentials",
      credentials instanceof ServiceAccountCredentials);

  FirebaseOptions options =
      new FirebaseOptions.Builder(firebaseOptions)
          .setProjectId("mock-project-id")
          .build();
  FirebaseApp app = FirebaseApp.initializeApp(options, "testVerifyIdTokenWithExplicitProjectId");
  try {
    FirebaseAuth.getInstance(app).verifyIdTokenAsync("foo").get();
    fail("Expected exception.");
  } catch (ExecutionException expected) {
    Assert.assertNotEquals(
        "com.google.firebase.FirebaseException: Must initialize FirebaseApp with a project ID "
            + "to call verifyIdToken()",
        expected.getMessage());
    assertTrue(expected.getCause() instanceof IllegalArgumentException);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:24,代码来源:FirebaseAuthTest.java

示例2: testDatabaseAuthVariablesAuthorization

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Test
public void testDatabaseAuthVariablesAuthorization() throws InterruptedException {
  Map<String, Object> authVariableOverrides = ImmutableMap.<String, Object>of(
      "uid", "test",
      "custom", "secret"
  );
  FirebaseOptions options =
      new FirebaseOptions.Builder(masterApp.getOptions())
          .setDatabaseAuthVariableOverride(authVariableOverrides)
          .build();
  FirebaseApp testUidApp = FirebaseApp.initializeApp(options, "testGetAppWithUid");
  FirebaseDatabase masterDb = FirebaseDatabase.getInstance(masterApp);
  FirebaseDatabase testAuthOverridesDb = FirebaseDatabase.getInstance(testUidApp);

  assertWriteSucceeds(masterDb.getReference());

  // "test" UID can only read/write to /test-uid-only and /test-custom-field-only locations.
  assertWriteFails(testAuthOverridesDb.getReference());
  assertWriteSucceeds(testAuthOverridesDb.getReference("test-uid-only"));
  assertReadSucceeds(testAuthOverridesDb.getReference("test-uid-only"));
  assertWriteSucceeds(testAuthOverridesDb.getReference("test-custom-field-only"));
  assertReadSucceeds(testAuthOverridesDb.getReference("test-custom-field-only"));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:24,代码来源:FirebaseDatabaseAuthTestIT.java

示例3: doInBackground

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Override
protected Boolean doInBackground(Void... voids) {
    FirebaseApp.initializeApp(mContext);
    MobileAds.initialize(mContext.getApplicationContext(), mContext.getResources().getString(R.string.app_id));
    FirebaseAnalytics.getInstance(mContext).setAnalyticsCollectionEnabled(true);
    FirebaseAnalytics.getInstance(mContext).setMinimumSessionDuration(2000);
    //dc.getGenres(null, null);

    AppVersionTracking current = new AppVersionTracking(BuildConfig.VERSION_CODE, BuildConfig.VERSION_NAME);

    if(!getAppPrefs().checkState()){
        getAppPrefs().saveOrUpdateVersionNumber(current);
        return false;
    }
    AppVersionTracking saved = getAppPrefs().getSavedVersions();
    if((BuildConfig.VERSION_CODE > saved.getCode())) {
        getAppPrefs().saveOrUpdateVersionNumber(current);
        return true;
    }
    return null;
}
 
开发者ID:wax911,项目名称:anitrend-app,代码行数:22,代码来源:MainPresenter.java

示例4: onCreate

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_test);

    FirebaseApp.initializeApp(this);
    FirebaseAuth.getInstance().addAuthStateListener(this);

    FirebaseAuth.getInstance().signInAnonymously()
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInAnonymously", task.getException());
                        Toast.makeText(TestActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });
}
 
开发者ID:crysxd,项目名称:shared-firebase-preferences,代码行数:27,代码来源:TestActivity.java

示例5: testGetTokenNoRefresh

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Test
public void testGetTokenNoRefresh() throws IOException, InterruptedException {
  MockGoogleCredentials credentials = new MockGoogleCredentials("mock-token");
  TokenRefreshDetector refreshDetector = new TokenRefreshDetector();
  credentials.addChangeListener(refreshDetector);
  credentials.refresh();
  assertEquals(1, refreshDetector.count);

  FirebaseOptions options = new FirebaseOptions.Builder()
      .setCredentials(credentials)
      .build();
  FirebaseApp app = FirebaseApp.initializeApp(options);

  JvmAuthTokenProvider provider = new JvmAuthTokenProvider(app, DIRECT_EXECUTOR);
  TestGetTokenListener listener = new TestGetTokenListener();
  provider.getToken(false, listener);
  assertToken(listener.get(), "mock-token", ImmutableMap.<String, Object>of());
  assertEquals(1, refreshDetector.count);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:20,代码来源:JvmAuthTokenProviderTest.java

示例6: login

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Before
public void login(){
    FirebaseApp.initializeApp(rule.getActivity());
    mAuth = FirebaseAuth.getInstance();

    mAuth.signInWithEmailAndPassword("[email protected]", "password")
            .addOnCompleteListener(rule.getActivity(), new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w("login activity", "signInWithEmail:failure", task.getException());

                    }
                }
            });
}
 
开发者ID:Socialate,项目名称:furry-sniffle,代码行数:20,代码来源:MainTest1.java

示例7: onCreate

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Override public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(this);
    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    Fabric.with(this, new Crashlytics());
    this.initializeInjector();
    this.initializeCalligraphy();
    this.initializeLeakDetection();
}
 
开发者ID:riteshakya037,项目名称:Subs,代码行数:10,代码来源:SubsApplication.java

示例8: onCreate

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    CalligraphyConfig.initDefault(
            new CalligraphyConfig.Builder().setDefaultFontPath("minyna.ttf").setFontAttrId(R.attr.fontPath)
                    .build());
    AndroidThreeTen.init(this);
    FirebaseApp.initializeApp(this);
    FirebaseMessaging.getInstance().subscribeToTopic("Power_Notifications");
}
 
开发者ID:riggaroo,项目名称:android-things-electricity-monitor,代码行数:11,代码来源:ElectricityApplication.java

示例9: initialize

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
private FirebaseApp initialize() {
	try (FileInputStream serviceAccount = new FileInputStream(getServiceAccountFilePath())) {
		FirebaseOptions options = new FirebaseOptions.Builder()
				.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
				.setDatabaseUrl(databaseUrl)
				.build();

		return FirebaseApp.initializeApp(options);
	} catch (IOException e) {
		System.out.println(e.getMessage());
		return null;
	}
}
 
开发者ID:trvlrch,项目名称:trvlr-backend,代码行数:14,代码来源:FirebaseService.java

示例10: testServiceAccountProjectId

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Test
public void testServiceAccountProjectId() throws IOException {
  FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
      .setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
      .build());
  Firestore firestore = FirestoreClient.getFirestore(app);
  assertEquals("mock-project-id", firestore.getOptions().getProjectId());

  firestore = FirestoreClient.getFirestore();
  assertEquals("mock-project-id", firestore.getOptions().getProjectId());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:FirestoreClientTest.java

示例11: testBucket

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Test
public void testBucket() throws IOException {
  FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
      .setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
      .setStorageBucket("mock-bucket-name")
      .build());
  Storage mockStorage = Mockito.mock(Storage.class);
  Bucket mockBucket = Mockito.mock(Bucket.class);
  Mockito.when(mockStorage.get("mock-bucket-name")).thenReturn(mockBucket);
  StorageClient client = new StorageClient(app, mockStorage);
  assertSame(mockBucket, client.bucket());
  assertSame(mockBucket, client.bucket("mock-bucket-name"));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:StorageClientTest.java

示例12: testInitAfterAppDelete

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Test
public void testInitAfterAppDelete() throws ExecutionException, InterruptedException,
    TimeoutException {
  FirebaseApp app = FirebaseApp.initializeApp(firebaseOptions, "testInitAfterAppDelete");
  FirebaseDatabase db1 = FirebaseDatabase.getInstance(app);
  assertNotNull(db1);
  app.delete();

  app = FirebaseApp.initializeApp(firebaseOptions, "testInitAfterAppDelete");
  FirebaseDatabase db2 = FirebaseDatabase.getInstance(app);
  assertNotNull(db2);
  assertNotSame(db1, db2);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:FirebaseDatabaseTest.java

示例13: setUpClass

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
  testApp = FirebaseApp.initializeApp(
      new FirebaseOptions.Builder()
          .setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
          .setDatabaseUrl(DB_URL)
          .build());
  // Obtain a new DatabaseConfig instance for testing. Since we are not connecting to an
  // actual Firebase database, it is necessary to use a stand-in DatabaseConfig here.
  config = TestHelpers.newTestConfig(testApp);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:DatabaseReferenceTest.java

示例14: setUpClass

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
  testApp = FirebaseApp.initializeApp(
      new FirebaseOptions.Builder()
          .setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
          .setDatabaseUrl("https://admin-java-sdk.firebaseio.com")
          .build());
  // Obtain a new DatabaseConfig instance for testing. Since we are not connecting to an
  // actual Firebase database, it is necessary to use a stand-in DatabaseConfig here.
  config = TestHelpers.newTestConfig(testApp);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:DataSnapshotTest.java

示例15: onCreate

import com.google.firebase.FirebaseApp; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    LocalBroadcastManager.getInstance(this);
    FirebaseApp.initializeApp(this);
    FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
            .setPersistenceEnabled(true)
            .build();
    FirebaseFirestore.getInstance().setFirestoreSettings(settings);
}
 
开发者ID:whirlwind-studios,项目名称:School1-Android,代码行数:11,代码来源:Application.java


注:本文中的com.google.firebase.FirebaseApp.initializeApp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。