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


Java FirebaseDatabase類代碼示例

本文整理匯總了Java中com.google.firebase.database.FirebaseDatabase的典型用法代碼示例。如果您正苦於以下問題:Java FirebaseDatabase類的具體用法?Java FirebaseDatabase怎麽用?Java FirebaseDatabase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FirebaseDatabase類屬於com.google.firebase.database包,在下文中一共展示了FirebaseDatabase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onLocationChanged

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@Override
public void onLocationChanged(Location location) {
    FirebaseAuth auth = FirebaseAuth.getInstance();
    String uid = auth.getCurrentUser().getUid();
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("users");
    ref.child(uid).child("location").setValue(new Loc(location.getLatitude(), location.getLongitude()));

    SharedPreferences prefs = context.getSharedPreferences("USER_DATA", 0);
    String group_id = prefs.getString("GROUP_ID", "");

    GeoHash geoHash = new GeoHash(location.getLatitude(), location.getLongitude());
    Map<String, Object> updates = new HashMap<String, Object>();
    updates.put("g", geoHash.getGeoHashString());
    updates.put("l", Arrays.asList(location.getLatitude(), location.getLongitude()));

    FirebaseDatabase.getInstance().getReference()
            .child("group_locations")
            .child(group_id)
            .child(uid)
            .setValue(updates);
    EventBus.getDefault().post(location);
}
 
開發者ID:mremondi,項目名稱:Hyke,代碼行數:23,代碼來源:HykeLocationManager.java

示例2: onCreateView

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView= inflater.inflate(R.layout.fragment_announcements, container, false);
    recycle=(RecyclerView)rootView.findViewById(R.id.recycle);

    recycle.setLayoutManager(new LinearLayoutManager(getActivity()));

    databaseReference3= FirebaseDatabase.getInstance().getReference().child("CHRD");

    get();


    recycle.setAdapter(firebaseRecyclerAdapter3);
    firebaseRecyclerAdapter3.notifyDataSetChanged();
    databaseReference3.keepSynced(true);
    recycle.invalidate();
    return rootView;
}
 
開發者ID:khokharnikunj8,項目名稱:SVNITChapters,代碼行數:21,代碼來源:CHRD.java

示例3: Context

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
/**
 * Vytvoří nový kontext apliakce
 *
 * @param databaseName Název databáze
 */
public Context(String databaseName, ResourceBundle resources) throws FileNotFoundException {
    this.resources = resources;
    this.appDirectory = new File(appDirs
        .getUserDataDir(CREDENTAILS_APP_NAME, CREDENTAILS_APP_VERSION, CREDENTILS_APP_AUTHOR));
    if (!appDirectory.exists()) {
        if (!appDirectory.mkdirs()) {
            logger.error("Nepodařilo se vytvořit složku aplikace, zavírám...");
            Platform.exit();
        }
    }
    logger.info("Používám pracovní adresář: {}", appDirectory.getPath());
    try {
        database = new SQLite(appDirectory.getPath() + SEPARATOR + databaseName);
    } catch (SQLException e) {
        throw new FileNotFoundException();
    }

    initFirebase();
    userManager = new UserManager(FirebaseDatabase.getInstance());
    initManagers();
}
 
開發者ID:stechy1,項目名稱:drd,代碼行數:27,代碼來源:Context.java

示例4: onCreate

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    Realm.init(this);
    RealmConfiguration config = new RealmConfiguration.Builder()
            .deleteRealmIfMigrationNeeded()
            //.schemaVersion(2) // Must be bumped when the schema changes
            //.migration(new RealmContactMigration()) // Migration to run instead of throwing an exception
            .name("default.realm").build();
    Realm.setDefaultConfiguration(config);

    if(database==null) {
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
        FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG);
    }

    database = FirebaseDatabase.getInstance();
    References.init(this, database);

    AppManager.getInstance().setContext(getApplicationContext());
    AppManager.getInstance().setCountry(Country.getCountryFromSIM(getApplicationContext()));

    // Initialize image loader
    initImageLoader(this);
}
 
開發者ID:AppHero2,項目名稱:Raffler-Android,代碼行數:27,代碼來源:AppApplication.java

示例5: 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

示例6: 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

示例7: onResume

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@Override
protected void onResume() {
    super.onResume();

    Query listenNewNotif = FirebaseDatabase
            .getInstance()
            .getReference(getString(R.string.firebase_key_last_notif))
            .child(getString(R.string.firebase_key_notif_id));
    listenNewNotif.keepSynced(true);
    final DatabaseHelper dbHelper = new DatabaseHelper(this);
    listenNewNotif.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            if(dbHelper.getUnreadCount()>0 && notifMenu!=null){
                notifMenu.setIcon(getResources().getDrawable(R.drawable.ic_notification_new));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d(TAG,databaseError.getMessage());
        }
    });
}
 
開發者ID:CSI-KJSCE,項目名稱:CSI-KJSCEOfficial,代碼行數:26,代碼來源:MainActivity.java

示例8: add

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
public void add(View view) {

        EditText title = (EditText) findViewById(R.id.editTitle);
        EditText description = (EditText) findViewById(R.id.editDescription);
         String titleMessage = title.getText().toString();
        //image64 = String of image
         String descripMessage = description.getText().toString();
        if(titleMessage != null  && imageB64 != null && descripMessage != null ) {
            blogContent chat = new blogContent(titleMessage, imageB64, descripMessage);
            FirebaseDatabase.getInstance().getReference(userUid).push().setValue(chat);
            toMainActivity();
            clearFields();
        }else{
            Toast.makeText(addActivity.this, "Please fill all options", Toast.LENGTH_LONG).show();

        }
    }
 
開發者ID:Th3VileOne,項目名稱:ReminderPrj,代碼行數:18,代碼來源:addActivity.java

示例9: run

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@SuppressLint("ApplySharedPref")
@Override
public void run() {
    //download all relevant data and sync with firebase
    try {
        FetchWakatimeData fetchWakatimeData = new FetchWakatimeData(getApplicationContext());
        WakatimeDataWrapper wakatimeDataWrapper = fetchWakatimeData.execute();
        Timber.d("Successfully download wakatimeData");
        User user = new TransformUtils(wakatimeDataWrapper, new User()).execute();
        //save to firebase
        Timber.d("Saving to firebase rdb");
        String uid = CacheUtils.getFirebaseUserId(getApplicationContext());
        if (uid != null) {
            FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
            DatabaseReference databaseReference = firebaseDatabase.getReference().child("users");
            databaseReference.child(uid).setValue(user);
        }
    } catch (Exception e) {
        Timber.e(e, "LeaderboardSyncTask failed");
        needsReschedule = true;
    }
    countDownLatch.countDown();
}
 
開發者ID:Protino,項目名稱:CodeWatch,代碼行數:24,代碼來源:WakatimeDataSyncJob.java

示例10: testDatabaseAuthVariablesNoAuthorization

import com.google.firebase.database.FirebaseDatabase; //導入依賴的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

示例11: onCreateView

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView= inflater.inflate(R.layout.fragment_announcements, container, false);
    recycle=(RecyclerView)rootView.findViewById(R.id.recycle);

    recycle.setLayoutManager(new LinearLayoutManager(getActivity()));

    databaseReference3= FirebaseDatabase.getInstance().getReference().child("GDG");
    get();
    image2=(ImageView)rootView.findViewById(R.id.image2);
   


    recycle.setAdapter(firebaseRecyclerAdapter3);
    firebaseRecyclerAdapter3.notifyDataSetChanged();
    databaseReference3.keepSynced(true);
    recycle.invalidate();
    return rootView;
}
 
開發者ID:khokharnikunj8,項目名稱:SVNITChapters,代碼行數:22,代碼來源:GDG.java

示例12: testNameAndRefForSnapshots

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@Test
public void testNameAndRefForSnapshots()
    throws TestFailure, ExecutionException, TimeoutException, InterruptedException {

  DatabaseReference ref = FirebaseDatabase.getInstance(masterApp).getReference();
  // Clear any data there
  new WriteFuture(ref, MapBuilder.of("foo", 10)).timedGet();

  DataSnapshot snap = TestHelpers.getSnap(ref);
  assertNull(snap.getKey());
  assertEquals(ref.toString(), snap.getRef().toString());
  DataSnapshot childSnap = snap.child("a");
  assertEquals("a", childSnap.getKey());
  assertEquals(ref.child("a").toString(), childSnap.getRef().toString());
  childSnap = childSnap.child("b/c");
  assertEquals("c", childSnap.getKey());
  assertEquals(ref.child("a/b/c").toString(), childSnap.getRef().toString());
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:19,代碼來源:DataTestIT.java

示例13: onBindViewHolder

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
@Override
public void onBindViewHolder(final ParticipantsViewHolder holder, int position) {
    String emailKey = participantEmails.get(position);
    final String userstat = String.valueOf(participantstatus.get(position));
    Log.d("userEmail", emailKey);
    FirebaseDatabase.getInstance().getReference().child(Constants.users).child(emailKey).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            User user = dataSnapshot.getValue(User.class);
            holder.nameView.setText(user.getDisplayName());
            holder.emailView.setText(user.getEmail()+"\n"+userstat);
            Glide.with(context).load(user.getDpUrl()).into(holder.imageView);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
開發者ID:picopalette,項目名稱:event-me,代碼行數:21,代碼來源:ParticipantsAdapter.java

示例14: addItem

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
private void addItem(HashMap<String, String> images, final Hotel item) {
    DatabaseReference itemsRef = FirebaseDatabase.getInstance().getReferenceFromUrl(Constants.FIREBASE_URL_ITEMS);
    itemsRef.keepSynced(true);
    item.setImagesUrls(images);
    itemsRef = itemsRef.push().getRef();

    itemsRef.setValue(item, new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
            mUploadProgressDialog.dismiss();
            if (databaseError == null) {
                Toast.makeText(AddActivity.this, "Item uploaded Successfully.", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(AddActivity.this, MainActivity.class)
                        .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            } else {
                Toast.makeText(AddActivity.this, "unable to add.", Toast.LENGTH_SHORT).show();

            }
        }
    });
}
 
開發者ID:Elbehiry,項目名稱:Viajes,代碼行數:22,代碼來源:AddActivity.java

示例15: GetYourRegistredOnes

import com.google.firebase.database.FirebaseDatabase; //導入依賴的package包/類
public void GetYourRegistredOnes ( Map<String,String> deineKontakte, Map<String, String> alleDownloads, String uid ) {
    back = new HashMap<String, Object>();       // kontaktnamen werden als boolean ausgelesen
    Set<String> s = new LinkedHashSet<String>(alleDownloads.keySet());        // key - nummer, value - uid
    Set<String> sss = new LinkedHashSet<String>(alleDownloads.values());        // key - nummer, value - uid
    Set<String> ss = new LinkedHashSet<String>(deineKontakte.values());       // key - name, value - nummer
    ss.retainAll(s);
    for (int i = 0; i < ss.size(); i++) {
        String x = ss.toArray()[i].toString();      // geht alle elemente durch, holt bei position i
        String y = "";
        for (int j = 0; j < s.size(); j++) {
            if (s.toArray()[j].toString().equals(x)) {
                y = sss.toArray()[j].toString();
                break;
            }
        }
        back.put(x, y );
    }
    DatabaseReference dbr = FirebaseDatabase.getInstance().getReference().getRoot();
    dbr.child("users").child(uid).child("contacts").setValue(back);
}
 
開發者ID:burliEnterprises,項目名稱:chapp-messenger,代碼行數:21,代碼來源:Contacts.java


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