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