本文整理匯總了Java中com.google.firebase.database.DatabaseReference.setValue方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseReference.setValue方法的具體用法?Java DatabaseReference.setValue怎麽用?Java DatabaseReference.setValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.firebase.database.DatabaseReference
的用法示例。
在下文中一共展示了DatabaseReference.setValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateIndex
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public Promise<Void, BError, Void> updateIndex(){
final Deferred<Void, BError, Void> deferred = new DeferredObject();
Map<String, String> values = new HashMap<String, String>();
String name = model.getMetaName();
String email = model.getMetaEmail();
String phoneNumber = model.metaStringForKey(BDefines.Keys.BPhone);
values.put(BDefines.Keys.BName, StringUtils.isNotEmpty(name) ? AbstractNetworkAdapter.processForQuery(name) : "");
values.put(BDefines.Keys.BEmail, StringUtils.isNotEmpty(email) ? AbstractNetworkAdapter.processForQuery(email) : "");
if (BDefines.IndexUserPhoneNumber && StringUtils.isNotBlank(phoneNumber))
values.put(BDefines.Keys.BPhone, AbstractNetworkAdapter.processForQuery(phoneNumber));
DatabaseReference ref = FirebasePaths.indexRef().child(entityId);
ref.setValue(values, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
if (firebaseError==null)
{
deferred.resolve(null);
}
else{
deferred.reject(getFirebaseError(firebaseError));
}
}
});
return deferred.promise();
}
示例2: sendData
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void sendData(String mealOrder) {
DatabaseReference node = FirebaseDatabase.getInstance().getReference().child("Orders").push();
///final String key = node.getKey();
String userId = getUid();
node.setValue(new Order(mealOrder,userId));
//final DatabaseReference mCustomerDatabase= FirebaseDatabase.getInstance().getReference().child("Users").child(userId);
//node.setValue(new Order(mealOrder,userId));
}
示例3: goOnline
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
/**
* Set the user online value to true.
*
* When firebase disconnect this will be auto change to false.
**/
public void goOnline(){
DatabaseReference userOnlineRef = FirebasePaths.userOnlineRef(entityId);
// Set the current state of the user as online.
// And add a listener so when the user log off from firebase he will be set as disconnected.
userOnlineRef.setValue(true);
userOnlineRef.onDisconnect().setValue(false);
}
示例4: updateBanList
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
/**
* update the banlist
* @param username the user's username
* @param operation the direction of operation (add/remove)
*/
private void updateBanList(String username, boolean operation) {
if (operation) {
UserDetails.addBanList(username);
} else {
UserDetails.removeBanList(username);
}
DatabaseReference df_2 = FirebaseDatabase.getInstance().getReference("banList");
df_2.setValue(UserDetails.getBanList());
}
示例5: save
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@OnClick(R.id.save_button)
public void save() {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue(dataEditText.getText().toString());
}
示例6: onCreate
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
setTitle("Add");
username = getIntent().getStringExtra("username");
userUid = getIntent().getStringExtra("userUid");
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("message");
myRef.setValue("Hello, World!");
}
示例7: addNewUserToFirebase
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
private void addNewUserToFirebase( final Spinner mGenderSpinner ) {
Map<String,Object> additions = new HashMap<>();
additions.put( "email", tempEmail );
additions.put( "suspended", false );
additions.put( "locked", false );
additions.put( "firstName", tempFirstName );
additions.put( "middleName", tempMiddleName );
additions.put( "lastName", tempLastName );
// Personal Info
additions.put( "bio", "" );
String tempDoB = "" + tempDoBYear + "-" + (tempDoBMonth < 10 ? "0" + tempDoBMonth : tempDoBMonth)
+ "-" + (tempDoBDay < 10 ? "0" + tempDoBDay : tempDoBDay);
additions.put( "birth_date", tempDoB );
if ( mGenderSpinner.getSelectedItem().toString().equals( "Male" ) ) {
additions.put( "gender", "male" );
}
else if ( mGenderSpinner.getSelectedItem().toString().equals( "Female" ) ) {
additions.put( "gender", "female" );
}
else {
additions.put( "gender", "non-binary" );
}
// Location
additions.put( "city", "" );
additions.put( "state", "" );
additions.put( "country", "" );
additions.put( "latitude", 0 );
additions.put( "longitude", 0 );
DatabaseReference ref = dbHelper.getDb().getReference().child(getString(R.string.sign_up_firebase_user)).child(dbHelper.getUser().getUid());
ref.setValue( additions );
}
示例8: push
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public Promise<BMessage, BError, BMessage> push(){
if (DEBUG) Timber.v("push");
final Deferred<BMessage, BError, BMessage> deferred = new DeferredObject<>();
// Getting the message ref. Will be created if not exist.
DatabaseReference ref = ref();
model.setEntityID(ref.getKey());
DaoCore.updateEntity(model);
ref.setValue(serialize(), ServerValue.TIMESTAMP, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) {
if (DEBUG) Timber.v("push message, onDone");
if (firebaseError == null) {
deferred.resolve(BMessageWrapper.this.model);
} else {
deferred.reject(getFirebaseError(firebaseError));
}
}
});
return deferred.promise();
}
示例9: onOptionsItemSelected
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.save_media) {
switch (mediaType) {
case 1: // text
DateTime now = DateTime.now();
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
JournalEntry currentEntry = new JournalEntry();
currentEntry.setCaption(entry_caption.getText().toString());
currentEntry.setType(mediaType);
currentEntry.setLat(ALLENDALE_LAT);
currentEntry.setLng(ALLENDATE_LNG);
currentEntry.setDate(fmt.print(now));
DatabaseReference savedEntry = entriesRef.push();
savedEntry.setValue(currentEntry);
Snackbar.make(entry_caption,
"Your entry is saved",
Snackbar.LENGTH_LONG).show();
break;
case 2: // photo
uploadMedia(mediaType, "image/jpeg", "photos");
break;
case 3: // audio
uploadMedia(mediaType, "audio/m4a", "audio");
break;
case 4: // video
uploadMedia(mediaType, "video/mp4", "videos");
break;
}
return true;
}
return false;
}
示例10: writeDataBase
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
private void writeDataBase(String message){
// Write a message to the database
FirebaseApp.initializeApp(getActivity());
FirebaseDatabase database = FirebaseDatabase.getInstance();
Calendar mCal = Calendar.getInstance();
CharSequence s = DateFormat.format("yyyy-MM-dd kk:mm:ss", mCal.getTime());
DatabaseReference myRef = database.getReference((String) s);
myRef.setValue(message);
}
示例11: addCategorieClick
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@OnClick(R.id.addCategorieButton)
public void addCategorieClick() {
String text = categoryEditText.getText().toString();
if(!text.isEmpty()) {
DatabaseReference dbRefChield = dbRef.push();
Category cat = new Category();
cat.setId(dbRefChield.getKey());
cat.setName(text);
dbRefChield.setValue(cat);
categoryEditText.setText("");
} else {
Snackbar.make(categoryEditText, R.string.empty_category_snackbar_text, Snackbar.LENGTH_LONG).show();
}
}
示例12: onCreateView
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FirebaseAuth auth = FirebaseAuth.getInstance();
final String uid = auth.getCurrentUser().getUid();
final DatabaseReference ref = database.getReference("users").child(uid).child("distress");
ref.setValue(dist);
final View rootView = inflater.inflate(R.layout.fragment_distress, null, false);
final TextView tvDistress = (TextView) rootView.findViewById(R.id.tvDistress);
ImageView ivDistressSignal = (ImageView) rootView.findViewById(R.id.ivDistressSignal);
ivDistressSignal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(dist) {
ref.setValue(false);
dist = false;
tvDistress.setText("All Clear");
}
else {
ref.setValue(true);
dist = true;
tvDistress.setText("Group Notified");
}
}
});
return rootView;
}
示例13: add
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
/**
* Add a new FollowRequest to Firebase.
* @param followRequest
*/
@Override
public void add(FollowRequest followRequest) {
DatabaseReference newRef = mFollowRequestRef.push();
String key = newRef.getKey();
followRequest.setKey(key);
newRef.setValue(followRequest);
}
示例14: saveStatus
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
private void saveStatus() {
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("status");
mDatabase.setValue(mETxtStatus.getText().toString());
}
示例15: saveUsername
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
private void saveUsername() {
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("nameAndSurname");
mDatabase.setValue(mETxtUsername.getText().toString());
}