本文整理匯總了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
}
}