當前位置: 首頁>>代碼示例>>Java>>正文


Java FirebaseDatabase.getInstance方法代碼示例

本文整理匯總了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;
}
 
開發者ID:gvsucis,項目名稱:mobile-app-dev-book,代碼行數:26,代碼來源:JournalFragment.java

示例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"));
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:24,代碼來源:FirebaseDatabaseAuthTestIT.java

示例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();
}
 
開發者ID:YoungPeacock,項目名稱:FantaF1,代碼行數:26,代碼來源:LoginActivity.java

示例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();
}
 
開發者ID:sindhu732,項目名稱:instagram_clone,代碼行數:18,代碼來源:HomeActivity.java

示例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;
}
 
開發者ID:wahibhaq,項目名稱:urdu-font-comparator-app,代碼行數:8,代碼來源:FirebaseModule.java

示例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;
}
 
開發者ID:yusufcakal,項目名稱:RestaurantApp,代碼行數:36,代碼來源:DetailPrıductFragment.java

示例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();

}
 
開發者ID:victoraldir,項目名稱:BuddyBook,代碼行數:12,代碼來源:ExampleInstrumentedTest.java

示例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());
}
 
開發者ID:micromasterandroid,項目名稱:androidadvanced,代碼行數:8,代碼來源:MainActivity.java

示例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();
}
 
開發者ID:Socialate,項目名稱:furry-sniffle,代碼行數:38,代碼來源:BookmarkActivity.java

示例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);
    }
}
 
開發者ID:projets2017cl,項目名稱:vc,代碼行數:11,代碼來源:LocalizationService.java

示例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");
            }
        });
    }
 
開發者ID:codingdojoangola,項目名稱:cda-app,代碼行數:34,代碼來源:ChatActivity.java

示例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);
}
 
開發者ID:SimonMarquis,項目名稱:FCM-toolbox,代碼行數:8,代碼來源:PresenceEventListener.java

示例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));

}
 
開發者ID:NarendraSickarwar,項目名稱:FirebasePost,代碼行數:14,代碼來源:AgroStarApplication.java

示例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);
    }
}
 
開發者ID:projets2017cl,項目名稱:vc,代碼行數:11,代碼來源:Product_TypeService.java

示例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
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:11,代碼來源:FirebaseDatabaseTestIT.java


注:本文中的com.google.firebase.database.FirebaseDatabase.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。