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


Java FirebaseApp类代码示例

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


FirebaseApp类属于com.google.firebase包,在下文中一共展示了FirebaseApp类的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: init

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
public void init (FirebaseApp firebaseApp) {
	mFirebaseApp = firebaseApp;
	String token = getFirebaseMessagingToken();

	dispatcher =
	new FirebaseJobDispatcher(new GooglePlayDriver(activity.getApplicationContext()));
	dispatcher.cancel("firebase-notify-in-time-UID");

	Utils.d("Firebase Cloud messaging token: " + token);

	// Perform task here..!
	if (KeyValueStorage.getValue("notification_complete_task") != "0") {
		try {
			JSONObject obj =
			new JSONObject(KeyValueStorage.getValue("notification_task_data"));

			Dictionary data = new Dictionary();
			Iterator<String> iterator = obj.keys();

			while (iterator.hasNext()) {
				String key = iterator.next();
				Object value = obj.opt(key);

				if (value != null) {
					data.put(key, value);
				}
			}

			Utils.callScriptCallback(
			KeyValueStorage.getValue("notification_complete_task"),
			"Notification", "TaskComplete", data);

		} catch (JSONException e) {

		}

		KeyValueStorage.setValue("notification_complete_task", "0");
	}
}
 
开发者ID:FrogSquare,项目名称:GodotFireBase,代码行数:40,代码来源:Notification.java

示例3: 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

示例4: initFirebase

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
/**
 * Inicializace firebase služby
 */
private void initFirebase() {
    try {
        InputStream serviceAccount = getClass().getResourceAsStream(FIREBASE_CREDENTAILS);

        Map<String, Object> auth = new HashMap<>();
        auth.put("uid", "my_resources");

        FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
            .setDatabaseUrl(FIREBASE_URL)
            .setDatabaseAuthVariableOverride(auth)
            .build();

        FirebaseApp.initializeApp(options);
    } catch (Exception e) {
        logger.info("Nemůžu se připojit k firebase", e);
    }
}
 
开发者ID:stechy1,项目名称:drd,代码行数:22,代码来源:Context.java

示例5: onPostExecute

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
@Override
protected void onPostExecute(String result) {
    if (!result.isEmpty() && APIDecoder.extractStatus(result) != 2) {
        Content.articles = APIDecoder.extractArticles(result);
        APICore.getInstance().write(ctx, APIConstants.CORE_ARTICLES, result);

        Collections.sort(Content.articles, new Comparator<Article>() {
            public int compare(Article a1, Article a2) {
                return a2.getDate().compareTo(a1.getDate());
            }
        });
        articlesAdapter.notifyDataSetChanged();
        APIConstants.ARTICLES_LOADED = true;

        FirebaseApp.initializeApp(ctx);
        APIClient.RegisterNotification registerNotification = new APIClient.RegisterNotification(ctx,
                FirebaseInstanceId.getInstance().getToken());
        registerNotification.execute();
    }
}
 
开发者ID:Snooze986,项目名称:SonoESEO-Android,代码行数:21,代码来源:ArticlesFragment.java

示例6: 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

示例7: login

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

    mAuth.signInWithEmailAndPassword("[email protected]", "sandile")
            .addOnCompleteListener(rule2.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,代码行数:21,代码来源:ViewOtherUserProfileTest.java

示例8: GoogleFirebaseBackend

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
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);
    }
}
 
开发者ID:kamax-io,项目名称:mxisd,代码行数:17,代码来源:GoogleFirebaseBackend.java

示例9: testInfoConnectedOnDisconnect

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
@Test
public void testInfoConnectedOnDisconnect()
    throws TestFailure, TimeoutException, InterruptedException {
  FirebaseApp app = IntegrationTestUtils.initApp("testInfoConnectedOnDisconnect");
  DatabaseReference ref = FirebaseDatabase.getInstance(app).getReference();

  // Wait until we're connected
  ReadFuture.untilEquals(ref.child(".info/connected"), true).timedGet();

  DatabaseConfig ctx = TestHelpers.getDatabaseConfig(app);
  RepoManager.interrupt(ctx);
  try {
    DataSnapshot snap =
        new ReadFuture(ref.child(".info/connected")).timedGet().get(0).getSnapshot();
    assertFalse((Boolean) snap.getValue());
  } finally {
    RepoManager.resume(ctx);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:20,代码来源:InfoTestIT.java

示例10: login

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

    mAuth.signInWithEmailAndPassword("[email protected]", "password")
            .addOnCompleteListener(rule2.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,代码行数:21,代码来源:ViewEntertainmentTest2.java

示例11: 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

示例12: testDatabaseAuthVariablesNoAuthorization

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
@Test
public void testDatabaseAuthVariablesNoAuthorization() throws InterruptedException {
  FirebaseOptions options =
      new FirebaseOptions.Builder(masterApp.getOptions())
          .setDatabaseAuthVariableOverride(null)
          .build();
  FirebaseApp testUidApp =
      FirebaseApp.initializeApp(options, "testServiceAccountDatabaseWithNoAuth");

  FirebaseDatabase masterDb = FirebaseDatabase.getInstance(masterApp);
  FirebaseDatabase testAuthOverridesDb = FirebaseDatabase.getInstance(testUidApp);

  assertWriteSucceeds(masterDb.getReference());

  assertWriteFails(testAuthOverridesDb.getReference("test-uid-only"));
  assertReadFails(testAuthOverridesDb.getReference("test-uid-only"));
  assertWriteFails(testAuthOverridesDb.getReference("test-custom-field-only"));
  assertReadFails(testAuthOverridesDb.getReference("test-custom-field-only"));
  assertWriteSucceeds(testAuthOverridesDb.getReference("test-noauth-only"));    
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:21,代码来源:FirebaseDatabaseAuthTestIT.java

示例13: initValideString

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
@Before
public void initValideString(){
    displayName = "Musa";
    fullName = "MusaRikhotso";

    FirebaseApp.initializeApp(rule.getActivity());
    mAuth = FirebaseAuth.getInstance();

    mAuth.signInWithEmailAndPassword("testgmail.com", "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,代码行数:23,代码来源:CreateProfileTest.java

示例14: assertAndUnwrapErrorHandlers

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
/**
 * Checks to see if any asynchronous error handlers added to the given FirebaseApp instance
 * have been activated. If so, this method will re-throw the root cause exception as a new
 * RuntimeException. Finally, this method also removes any error handlers added previously by
 * the wrapForErrorHandling method. Invoke this method in integration tests from an After
 * test fixture.
 *
 * @param app AFireabseApp instance already instrumented by wrapForErrorHandling
 */
public static void assertAndUnwrapErrorHandlers(FirebaseApp app) {
  DatabaseConfig context = getDatabaseConfig(app);
  DefaultRunLoop runLoop = (DefaultRunLoop) context.getRunLoop();
  try {
    TestExceptionHandler handler = (TestExceptionHandler) runLoop.getExceptionHandler();
    Throwable error = handler.throwable.get();
    if (error != null) {
      throw new RuntimeException(error);
    }

    handler = (TestExceptionHandler) CoreTestHelpers.getEventTargetExceptionHandler(context);
    error = handler.throwable.get();
    if (error != null) {
      throw new RuntimeException(error);
    }
  } finally {
    CoreTestHelpers.setEventTargetExceptionHandler(context, null);
    runLoop.setExceptionHandler(null);
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:30,代码来源:TestHelpers.java

示例15: testGetTokenError

import com.google.firebase.FirebaseApp; //导入依赖的package包/类
@Test
public void testGetTokenError() throws InterruptedException {
  MockGoogleCredentials credentials = new MockGoogleCredentials("mock-token") {
    @Override
    public AccessToken refreshAccessToken() throws IOException {
      throw new RuntimeException("Test error");
    }
  };
  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(true, listener);
  assertEquals("java.lang.RuntimeException: Test error", listener.get());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:19,代码来源:JvmAuthTokenProviderTest.java


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