本文整理汇总了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);
}
}
示例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"));
}
示例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;
}
示例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();
}
}
});
}
示例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);
}
示例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());
}
}
});
}
示例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();
}
示例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");
}
示例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;
}
}
示例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());
}
示例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"));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}