本文整理匯總了Java中com.google.firebase.database.DatabaseReference.getKey方法的典型用法代碼示例。如果您正苦於以下問題:Java DatabaseReference.getKey方法的具體用法?Java DatabaseReference.getKey怎麽用?Java DatabaseReference.getKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.firebase.database.DatabaseReference
的用法示例。
在下文中一共展示了DatabaseReference.getKey方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFakeMembers
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public static ArrayList<Member> getFakeMembers(DatabaseReference databaseReference) {
ArrayList<Member.Disponibility> disponibilities = new ArrayList<Member.Disponibility>();
disponibilities.add(Member.Disponibility.FULL_TIME);
disponibilities.add(Member.Disponibility.FREELANCER);
ArrayList<String> programmingLangs = new ArrayList<>();
programmingLangs.add("C#");
programmingLangs.add("C++");
programmingLangs.add("Java");
ArrayList<String> technologies = new ArrayList<>();
technologies.add("ASP.NET");
technologies.add("WPF");
String id = databaseReference.getKey();
for (int i = 0; i < 50; i++) {
Member member = new Member(id, "Henrick Kakutalua", BeltColor.WHITE, disponibilities,
12, programmingLangs, technologies, "");
mMembers.add(member);
}
return mMembers;
}
示例2: addMessage
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public static void addMessage(ChatMessage chatMessage) {
DatabaseReference chatMsgRef = DatabaseRouter.getConversationRef(chatMessage.getConversationId()).child(DATA).push();
chatMessage.id = chatMsgRef.getKey();
// chatMsgRef.setValue(chatMessage);
// ShoudBeDoneOnServer.updateChatMessageInInbox(chatMessage);
HashMap<String, Object> childUpdates = new HashMap<>();
String msgPath = Fire.db.getPathFromRef(chatMsgRef);
childUpdates.put(msgPath, chatMessage);
DatabaseReference inboxItemRef = DatabaseRouter.getInboxRef().child(DATA).child(chatMessage.getConversationId());
// inboxItemRef.setValue(chatMessage);
childUpdates.put(Fire.db.getPathFromRef(inboxItemRef.child("text")), chatMessage.getText());
childUpdates.put(Fire.db.getPathFromRef(inboxItemRef.child("name")), chatMessage.getUserName());
childUpdates.put(Fire.db.getPathFromRef(inboxItemRef.child("timestamp")), chatMessage.getTimestamp());
Fire.db.getBaseRef().updateChildren(childUpdates);
}
示例3: getRandomNode
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public static List<DatabaseReference> getRandomNode(FirebaseApp app, int count) {
FirebaseDatabase database = FirebaseDatabase.getInstance(app);
ImmutableList.Builder<DatabaseReference> builder = ImmutableList.builder();
String name = null;
for (int i = 0; i < count; i++) {
if (name == null) {
DatabaseReference ref = database.getReference().push();
builder.add(ref);
name = ref.getKey();
} else {
builder.add(database.getReference().child(name));
}
}
return builder.build();
}
示例4: createItem
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void createItem(String itemName, String itemDescription, int itemPrice, boolean itemUrgent) {
ShoppingListItem listItem = new ShoppingListItem(name, itemName, itemDescription, itemPrice, itemUrgent);
DatabaseReference ref = dbRef.child("items").push();
ref.setValue(listItem);
lastAddedOwnKey = ref.getKey();
// sendItemNotification(listItem);
}
示例5: pushToFirebaseOnAddingGroup
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public static void pushToFirebaseOnAddingGroup(String groupName, DateTime dateTime, final ArrayList<String> usersToAdd) {
DatabaseReference pushedGroupRef = groupDataRef.push();
final String pushedGroupKey = pushedGroupRef.getKey();
pushedGroupRef.child("groupName").setValue(groupName);
pushedGroupRef.child("members").setValue(usersToAdd);
pushedGroupRef.child("endTime").setValue(dateTime);
// Loop through Firebase users to find group members. If found,
// put the unique group key in the user node.
userDataRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childNode : dataSnapshot.getChildren()) {
for (String user : usersToAdd) {
if (user.equals(childNode.getKey())) {
userDataRef.child(childNode.getKey()).child("groups").child(pushedGroupKey).setValue(pushedGroupKey);
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例6: 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);
}
示例7: addPlant
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
/**
* Add a new plant to a user's plant list in the database
* @param context - current app context
* @param name - name of the plant
* @param species - the plant's species
* @param birthday - the plant's birthday
* @param height - the plant's height
* @param bmp - the plant's picture
*/
public boolean addPlant(final Context context, String name, String species, long birthday, double height, final Bitmap bmp) {
showProgressDialog(context, context.getString(R.string.loading_text));
// reject plant addition if species is null
if ((species == null) || species.equals("") || (name == null) || name.equals("")) {
Toast.makeText(context, R.string.toast_invalid_plant_input, Toast.LENGTH_SHORT).show();
hideProgressDialog();
return false;
}
else if (getPlantsNumber() > 999) {
Toast.makeText(context, R.string.toast_plant_limit_exceeded, Toast.LENGTH_SHORT).show();
hideProgressDialog();
return false;
}
else if (mSpeciesCache.containsKey(species)) {
// If the user typed a common name, fetch the scientific name
species = mSpeciesCache.get(species);
}
else if (!mSpeciesCache.containsValue(species)) {
// The user must have entered neither the scientific nor the common name
hideProgressDialog();
return false;
}
final String userId = getUserId();
if (userId != null) {
DatabaseReference plantRef = getAllPlantsReference().push();
final String plantId = plantRef.getKey();
final Plant plant = new Plant(plantId, name, species, birthday, height);
plantRef.setValue(plant).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (!task.isSuccessful()) {
Toast.makeText(context, "Plant add failed, try again", Toast.LENGTH_SHORT).show();
} else {
setPlantsNumber(++mPlantsNumber);
updatePlantImage(0, 0, plantId, bmp);
setAddedNumber(getAddedCount() + 1);
updateUserRating();
}
}
});
}
hideProgressDialog();
return true;
}
示例8: sendData
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
public void sendData(String title, String body,String ingre, Float latitude, Float longitude,String url,Float price) {
DatabaseReference node = FirebaseDatabase.getInstance().getReference().child("Serving").push();
final String key = node.getKey();
String userId = getUid();
node.setValue(new Serve(title,body, ingre,latitude,longitude, url, key, userId, price));
final DatabaseReference mCustomerDatabase= FirebaseDatabase.getInstance().getReference().child("Users").child(userId);
/*ValueEventListener valueEventListener = mCustomerDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0){
Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
if(map.get("foodId")==null){
map.put("foodId",key);
mCustomerDatabase.updateChildren(map);
}else{
DatabaseReference foodId = mCustomerDatabase.child("foodId").push();
foodId.setValue(key);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});*/
mCustomerDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0){
Map<String, Object> map = (Map<String, Object>) dataSnapshot.getValue();
if(map.get("foodId")==null){
map.put("foodId",key);
mCustomerDatabase.updateChildren(map);
}else{
DatabaseReference foodId = mCustomerDatabase.child("foodId").push();
foodId.setValue(key);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
node.setValue(new Serve(title,body,ingre,latitude,longitude, url, key, userId,price));
}
示例9: onActivityResult
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == GALLERY_PICK && resultCode == RESULT_OK){
Uri imageUri = data.getData();
final String current_user_ref = "messages/" + mCurrentUserId + "/" + mChatUser;
final String chat_user_ref = "messages/" + mChatUser + "/" + mCurrentUserId;
DatabaseReference user_message_push = mRootRef.child("messages")
.child(mCurrentUserId).child(mChatUser).push();
final String push_id = user_message_push.getKey();
StorageReference filepath = mImageStorage.child("message_images").child( push_id + ".jpg");
filepath.putFile(imageUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if(task.isSuccessful()){
String download_url = task.getResult().getDownloadUrl().toString();
Map messageMap = new HashMap();
messageMap.put("message", download_url);
messageMap.put("seen", false);
messageMap.put("type", "image");
messageMap.put("time", ServerValue.TIMESTAMP);
messageMap.put("from", mCurrentUserId);
Map messageUserMap = new HashMap();
messageUserMap.put(current_user_ref + "/" + push_id, messageMap);
messageUserMap.put(chat_user_ref + "/" + push_id, messageMap);
mChatMessageView.setText("");
mRootRef.updateChildren(messageUserMap, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if(databaseError != null){
Log.d("CHAT_LOG", databaseError.getMessage().toString());
}
}
});
}
}
});
}
}
示例10: sendMessage
import com.google.firebase.database.DatabaseReference; //導入方法依賴的package包/類
private void sendMessage() {
String message = mChatMessageView.getText().toString();
if(!TextUtils.isEmpty(message)){
String current_user_ref = "messages/" + mCurrentUserId + "/" + mChatUser;
String chat_user_ref = "messages/" + mChatUser + "/" + mCurrentUserId;
DatabaseReference user_message_push = mRootRef.child("messages")
.child(mCurrentUserId).child(mChatUser).push();
String push_id = user_message_push.getKey();
Map messageMap = new HashMap();
messageMap.put("message", message);
messageMap.put("seen", false);
messageMap.put("type", "text");
messageMap.put("time", ServerValue.TIMESTAMP);
messageMap.put("from", mCurrentUserId);
Map messageUserMap = new HashMap();
messageUserMap.put(current_user_ref + "/" + push_id, messageMap);
messageUserMap.put(chat_user_ref + "/" + push_id, messageMap);
mChatMessageView.setText("");
mRootRef.child("Chat").child(mCurrentUserId).child(mChatUser).child("seen").setValue(true);
mRootRef.child("Chat").child(mCurrentUserId).child(mChatUser).child("timestamp").setValue(ServerValue.TIMESTAMP);
mRootRef.child("Chat").child(mChatUser).child(mCurrentUserId).child("seen").setValue(false);
mRootRef.child("Chat").child(mChatUser).child(mCurrentUserId).child("timestamp").setValue(ServerValue.TIMESTAMP);
mRootRef.updateChildren(messageUserMap, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if(databaseError != null){
Log.d("CHAT_LOG", databaseError.getMessage().toString());
}
}
});
}
}