本文整理汇总了Java中com.google.firebase.database.FirebaseDatabase.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java FirebaseDatabase.getInstance方法的具体用法?Java FirebaseDatabase.getInstance怎么用?Java FirebaseDatabase.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.database.FirebaseDatabase
的用法示例。
在下文中一共展示了FirebaseDatabase.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_journal_list, container, false);
// Set the adapter
if (view instanceof RecyclerView) {
FirebaseDatabase dbRef = FirebaseDatabase.getInstance();
FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();
DatabaseReference userRef = dbRef.getReference(user.getUid());
userRef.addChildEventListener (chEvListener);
userRef.addValueEventListener(valEvListener);
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) view;
if (mColumnCount <= 1) {
recyclerView.setLayoutManager(new LinearLayoutManager(context));
} else {
recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
}
adapter = new JournalAdapter(allTrips, mListener);
recyclerView.setAdapter(adapter);
}
return view;
}
示例2: testDatabaseAuthVariablesAuthorization
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的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: setContent
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
private void setContent() {
setContentView(R.layout.activity_login);
screen = (RelativeLayout)findViewById(R.id.rl);
ColorDrawable[] color = {new ColorDrawable(getResources().getColor(R.color.colorAccent)), new ColorDrawable(getResources().getColor(R.color.colorPrimary)) };
TransitionDrawable trans = new TransitionDrawable(color);
screen.setBackgroundDrawable(trans);
trans.startTransition(1800);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
mGoogleApiClient = new GoogleApiClient.Builder(getBaseContext())
.enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso).build();
mAuth = FirebaseAuth.getInstance();
FirebaseDatabase database = FirebaseDatabase.getInstance();
root= database.getReference("room_names");
loadRooms();
new CountDownTimer(2500, 1000) {
public void onTick(long millisUntilDone) { }
public void onFinish() {
currentUser = mAuth.getCurrentUser();
updateUI(currentUser);
}
}.start();
}
示例4: onCreate
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_home);
setContentView(R.layout.fragment_feed);
Log.d(TAG, "onCreate: starting");
setupBottomNavigationBar();
mAuth = FirebaseAuth.getInstance();
mDatabase = FirebaseDatabase.getInstance();
mFeed = findViewById(R.id.myFeed);
Log.d(TAG, mFeed.toString());
listAdapter = new MainFeedListAdapter(HomeActivity.this, R.layout.layout_feed_list_item, posts);
mFeed.setAdapter(listAdapter);
downloadMyFeed();
}
示例5: provideFirebaseDatabase
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Singleton
@Provides
FirebaseDatabase provideFirebaseDatabase() {
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
firebaseDatabase.setPersistenceEnabled(true); //for offline access
return firebaseDatabase;
}
示例6: onCreateView
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_detail_product, container, false);
android_id = Settings.Secure.getString(getActivity().getContentResolver(), Settings.Secure.ANDROID_ID);
FirebaseApp.initializeApp(getActivity());
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("basket").child(android_id);
btnAddBasket = (FlatButton) view.findViewById(R.id.btnAddBasket);
btnAddBasket.setOnClickListener(this);
progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Ürün Yükleniyor..");
progressDialog.show();
progressDialog.hide();
//OnSuucese kaydet
sliderLayout = (SliderLayout) view.findViewById(R.id.slider);
tvPrice = (TextView) view.findViewById(R.id.tvPrice);
etPiece = (EditText) view.findViewById(R.id.etPiece);
etPiece.addTextChangedListener(this);
imageList = new ArrayList<>();
productIdExstra = getArguments().getInt("id");
urlDetail+=productIdExstra;
Request request = new Request(getActivity(), urlDetail, com.android.volley.Request.Method.GET);
request.requestVolley(this);
return view;
}
示例7: useAppContext
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Test
@Ignore
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.quartzodev.buddybook", appContext.getPackageName());
FirebaseDatabase.getInstance();
}
示例8: save
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@OnClick(R.id.save_button)
public void save() {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue(dataEditText.getText().toString());
}
示例9: onCreate
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bookmark);
// Initialize references to views
mToolbar = findViewById(R.id.bookmarkPageToolBar);
mEntertainmentSpotRecyclerView = findViewById(R.id.entertainmentSpotRecyclerView);
// Initialize RecyclerView
mEntertainmentSpotRecyclerView.setHasFixedSize(true);
mEntertainmentSpotRecyclerView.setLayoutManager(new LinearLayoutManager(this));
// Initialize Firebase components
FirebaseApp.initializeApp(this);
mFireBaseDatabase = FirebaseDatabase.getInstance();
mFirebaseAuth = FirebaseAuth.getInstance();
mEventsDatabaseReference = mFireBaseDatabase.getReference().child("Entertainments");
mUsersDatabaseReference = mFireBaseDatabase.getReference().child("users");
mLikesDatabaseReference = mFireBaseDatabase.getReference().child("Likes");
mBookmarksDatabaseReference = mFireBaseDatabase.getReference().child("Bookmarks");
mUsersDatabaseReference.keepSynced(true);
mEventsDatabaseReference.keepSynced(true);
mLikesDatabaseReference.keepSynced(true);
mBookmarksDatabaseReference.keepSynced(true);
setSupportActionBar(mToolbar);
if(getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Bookmarks");
}
//starting intent service
startIntentService();
}
示例10: LocalizationService
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
LocalizationService() {
try {
this.test = new FireBase_DataBase();
FirebaseDatabase database = FirebaseDatabase.getInstance();
ref = database.getReference("");
LocalizationRef = ref.child("Localization");
} catch (FileNotFoundException ex) {
Logger.getLogger(LocalizationService.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例11: verifyPresence
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
public void verifyPresence(){
final FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference myConnectionsRef = database.getReference().child("user").child(userID).child("status");
final DatabaseReference lastOnlineRef = database.getReference().child("user").child(userID).child("lastOnline");
final DatabaseReference connectedRef = database.getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean connected = snapshot.getValue(Boolean.class);
if (connected) {
DatabaseReference con = myConnectionsRef.push();
// when this device disconnects, remove it
con.onDisconnect().removeValue();
// when I disconnect, update the last time I was seen online
lastOnlineRef.onDisconnect().setValue(ServerValue.TIMESTAMP);
// add this device to my connections list
// this value could contain info about the device or a timestamp too
//con.setValue(Boolean.TRUE);
con.setValue(Boolean.TRUE);
}
}
@Override
public void onCancelled(DatabaseError error) {
System.err.println("Listener was cancelled at .info/connected");
}
});
}
示例12: PresenceEventListener
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
PresenceEventListener(Context context) {
this.context = context.getApplicationContext();
String uuid = Uuid.get(context);
FirebaseDatabase database = FirebaseDatabase.getInstance();
presenceReference = database.getReference(".info/connected");
connectionRef = database.getReference("devices/" + uuid);
}
示例13: onCreate
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
Timber.plant(new Timber.DebugTree());
FirebaseApp.initializeApp(this);
FacebookSdk.setApplicationId(getString(R.string.facebook_app_id));
FacebookSdk.sdkInitialize(this);
instance = this;
database = FirebaseDatabase.getInstance();
startService(CommentTableService.createIntent(this));
}
示例14: Product_TypeService
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
Product_TypeService() {
try {
this.test = new FireBase_DataBase();
FirebaseDatabase database = FirebaseDatabase.getInstance();
ref = database.getReference("");
Product_TypeRef = ref.child("Product_Type");
} catch (FileNotFoundException ex) {
Logger.getLogger(Product_TypeService.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例15: testDatabaseUrlWithPathInGetInstance
import com.google.firebase.database.FirebaseDatabase; //导入方法依赖的package包/类
@Test
public void testDatabaseUrlWithPathInGetInstance() {
FirebaseApp app = appWithoutDbUrl("dbUrlWithPathInGetInstance");
try {
FirebaseDatabase.getInstance(app, IntegrationTestUtils.getDatabaseUrl()
+ "/paths/are/not/allowed");
fail("no error thrown for DB URL with path");
} catch (DatabaseException expected) { // ignore
}
}