當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。