本文整理汇总了Java中com.firebase.client.Firebase.updateChildren方法的典型用法代码示例。如果您正苦于以下问题:Java Firebase.updateChildren方法的具体用法?Java Firebase.updateChildren怎么用?Java Firebase.updateChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.firebase.client.Firebase
的用法示例。
在下文中一共展示了Firebase.updateChildren方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addValuesFireBase
import com.firebase.client.Firebase; //导入方法依赖的package包/类
public void addValuesFireBase(String temperature, String humidade, double latitude, double longitude, String currentDateandTime, String district){
mRef = new Firebase("https://livingcityapp.firebaseio.com");
Firebase usersRef = mRef.child(currentDateandTime);
SimpleDateFormat hora = new SimpleDateFormat("HH:mm:ss");
String currenthora = hora.format(new Date());
Map<String, String> map = new HashMap<>();
map.put("Temperature",temperature);
map.put("Humidade", humidade);
map.put("Hora",currenthora);
map.put("Latitude", Double.toString(latitude));
map.put("Longitude", Double.toString(longitude));
map.put("Distrito", district);
Map<String, Object> mapaCompleto = new HashMap<>();
mapaCompleto.put(currenthora, map);
usersRef.updateChildren(mapaCompleto);
}
示例2: onActivityResult
import com.firebase.client.Firebase; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_PLACE_PICKER) {
if (resultCode == Activity.RESULT_OK) {
Place place = PlacePicker.getPlace(this,data);
Map<String,Object>shareLocation=new HashMap<>();
shareLocation.put("time", ServerValue.TIMESTAMP);
//get data from Login Activity
Intent in=getIntent();
Bundle b=in.getExtras();
String name=b.getString("name");
Long number=b.getLong("contact_no");
Toast.makeText(this,"name: "+name+" number: "+number.toString(),Toast.LENGTH_SHORT).show();
//Map<String,Long>userData=new HashMap<>();
//userData.put(name,number);
Map userData=new HashMap();
userData.put(name,number);
mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId()).setValue(shareLocation);
Firebase fire=new Firebase(FIREBASE_URL);
Firebase userRef=fire.child(FIREBASE_ROOT_NODE);
Firebase people=userRef.child(place.getId());
people.updateChildren(userData);
//mFirebase.child(FIREBASE_ROOT_NODE).child(place.getId());
//mFirebase.setValue(userData);
Toast.makeText(this,"added:"+name+" "+number,Toast.LENGTH_SHORT).show();
//Toast.makeText(this,"added location",Toast.LENGTH_SHORT).show();
} else if (resultCode == PlacePicker.RESULT_ERROR) {
Toast.makeText(this, "Places API failure! Check that the API is enabled for your key",
Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
示例3: handleIncomingMessage
import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
* Handle the incoming message from the nearby device. Parse the message to retrieve the appropriate data.
*/
private void handleIncomingMessage(Message message) {
LogUtils.LOGE("***> message", DeviceMessage.fromNearbyMessage(message).getMessageBody());
String[] messageParts = DeviceMessage.fromNearbyMessage(message).getMessageBody().split(Pattern.quote("|"));
if (messageParts.length == 0) {
LogUtils.LOGE("***> error", "error parsing message");
return;
}
mFirebaseUid = messageParts[0];
mDeviceNum = Integer.valueOf(messageParts[1]);
mTotalDevices = Integer.valueOf(messageParts[2]);
String deviceId = messageParts[3];
if (!PreferencesUtils.getBoolean(mActivity, R.string.key_is_connected, false)) {
// Update Firebase and remove the old FirebaseUid
String currentFirebaseUid = PreferencesUtils.getString(mActivity, R.string.key_firebase_uid, "");
LogUtils.LOGE("***> handleIncomingMessage", "remove firebase uid:" + currentFirebaseUid);
Firebase userChallengeRef = new Firebase(Constants.FIREBASE_URL_USERS).child(currentFirebaseUid);
userChallengeRef.removeValue();
}
// Update the shared preferences
PreferencesUtils.setString(mActivity, R.string.key_firebase_uid, mFirebaseUid);
PreferencesUtils.setInt(mActivity, R.string.key_total_devices, mTotalDevices);
PreferencesUtils.setInt(mActivity, R.string.key_device_number, mDeviceNum);
PreferencesUtils.setBoolean(mActivity, R.string.key_is_connected, true);
// Display the message
displayMessage();
// Update the background color
setInitialValues();
// Generate next message, based on Firebase
getNextDeviceFirebase();
// Update connected status on Firebase
Map<String, Object> device = new HashMap<>();
device.put(Constants.FIREBASE_PROPERTY_CONNECTED, true);
Firebase deviceRef = new Firebase(Constants.FIREBASE_URL_DEVICES).child(mFirebaseUid).child(deviceId);
deviceRef.updateChildren(device);
deviceRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Device d = dataSnapshot.getValue(Device.class);
LogUtils.LOGE("***> deviceRef", "here");
if (d == null) {
LogUtils.LOGE("***> setupFirebase", "reset device");
MainActivity.resetDevice();
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
if (mDeviceNum < mTotalDevices) {
// Change the display text
mIntroConnectDevice.setText(mActivity.getString(R.string.text_connect_device, mDeviceNum + 1));
// Change text/button action
mDiscover.setOnClickListener(mConnectedClickListener);
} else {
mIntroConnectDevice.setVisibility(View.GONE);
mDiscover.setVisibility(View.GONE);
}
unsubscribe();
}
示例4: setupFirebase
import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
* Setup Firebase for the user and connected devices
*
* Update the existing user data with the number of devices selected on the previous screen
* Add the devices based on the selection
* Generate the message for the next device
*/
private void setupFirebase() {
// Update Firebase to include the total number of devices
if (!TextUtils.isEmpty(mFirebaseUid)) {
Map<String, Object> profile = new HashMap<>();
profile.put(Constants.FIREBASE_PROPERTY_NUMBER_DEVICES, mTotalDevices);
Firebase userRef = new Firebase(Constants.FIREBASE_URL_USERS).child(mFirebaseUid);
userRef.updateChildren(profile);
LogUtils.LOGE("***> setupFirebase", "update firebase uid:" + mFirebaseUid);
// Add device ids to Firebase
for (int i = 0; i < PreferencesUtils.getInt(mActivity, R.string.key_total_devices, 1); i++) {
// If the challengeCode is empty, then push a new value to the database
Firebase deviceRef = new Firebase(Constants.FIREBASE_URL_DEVICES).child(mFirebaseUid);
final Firebase newDeviceRef = deviceRef.push();
mDeviceIds[i] = newDeviceRef.getKey();
final int currentDeviceNumber = i + 1;
LogUtils.LOGE("***> new device #" + currentDeviceNumber, mDeviceIds[i]);
Device device = new Device(mDeviceIds[i], i + 1, mDeviceNum == currentDeviceNumber);
newDeviceRef.setValue(device);
newDeviceRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Device d = dataSnapshot.getValue(Device.class);
if (d != null) {
LogUtils.LOGE("***> child updated", "id: " + d.getDeviceId());
LogUtils.LOGE("***> child updated", "number: " + d.getDeviceNumber());
LogUtils.LOGE("***> child updated", "connected: " + d.isConnected());
LogUtils.LOGE("***> child updated", "next: " + currentDeviceNumber);
// Hide the button and show the message for the first device
if (d.isConnected() && d.getDeviceNumber() > 1) {
PreferencesUtils.setBoolean(mActivity, R.string.key_message_received, true);
LogUtils.LOGE("***> child updated", "unpublished: " + currentDeviceNumber);
unpublish();
mDiscover.setVisibility(View.GONE);
mIntroConnectDevice.setText(mActivity.getString(R.string.text_message_received));
}
} else {
if (!PreferencesUtils.getBoolean(mActivity, R.string.key_device_reset_done, false)) {
LogUtils.LOGE("***> setupFirebase", "reset device");
MainActivity.resetDevice();
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
// Create the message for the next device
if (i == mDeviceNum) {
LogUtils.LOGE("***> device", "message created");
String message = mActivity.getString(R.string.message_body, mFirebaseUid, mDeviceNum + 1,
mTotalDevices, newDeviceRef.getKey());
mDeviceInfoMessage = DeviceMessage.newNearbyMessage(
InstanceID.getInstance(mActivity.getApplicationContext()).getId(), message);
}
}
}
}