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