two apps in same firebase project - how can I access each one?

22 views
Skip to first unread message

Liz G

unread,
Jun 19, 2018, 3:25:29 PM6/19/18
to Firebase Google Group
Hello:

I have a firebase project that has two apps, rider and driver, for instance.  If I save destination in the rider side of the project,  how can I access it from the driver side of the project.  The two apps share the same google-service.json but have different AppIDs.

Here is an example of the database:

{
"Requests" : {
"khVbT88fA8YUmt5qv5LG0OTVZEm1" : {
".priority" : "f8118cjyt8",
"g" : "f8118cjyt8",
"l" : [ 45.2702827, -66.0526581 ]
}
},
"Tokens" : {
"khVbT88fA8YUmt5qv5LG0OTVZEm1" : {
"token" : "dubFldULQiw:APA91bH1LTi7M8j9zlZZAe6_yQ_YWseNUki4hcksDgmbN7IktWIa1OAVUMgG58hZU0p-7DvF1dig0vMfd9cE4ihqn_YsBAARhrIpA3Nmhd49yaUxHLP9W-1VXy_vRFSt6SWhNblcKqoh"
},
"vP9r4F2yDWRRuvKjRiQvMEXVuoK2" : {
"token" : "d3kBY1pswJo:APA91bFoqFRpZLO6DPCy5w4Xucg_rdMbblJ4ndV6W4AnUxWl4OSmu3XFQX98gMnleOXBkuIkdaEqXzpasO36NlU5CEa3CSDOCxpSqeFlCYm-IvYqQ0zFvxIRDCR9p2_u6mBkTyq_NOmx"
}
},
"Users" : {
"Drivers" : {
"RAFIxzcAYjNNIU15IMIVHfr0CMC2" : {
"email" : "dri...@me.com",
"name" : "LizG",
"password" : "zzzzzz",
"phone" : "6532525"
},
"vP9r4F2yDWRRuvKjRiQvMEXVuoK2" : {
"email" : "dri...@me.com",
"name" : "Batman",
"password" : "zzzzzz",
"phone" : "5326598",
"rates" : "0"
}
},
"Riders" : {
"khVbT88fA8YUmt5qv5LG0OTVZEm1" : {
"Ryydes" : {
"Coordinates" : {
"destination" : {
"searchBar" : "84 Orange St, Saint John, NB E2L 1M4, Canada",
"tapOnMap" : "98 Sydney St, Saint John, NB E2L 2L9, Canada"
}
}
},
"avatarUrl" : "",
"email" : "ri...@me.com",
"name" : "Rider",
"password" : "zzzzzz",
"phone" : "5551211",
"rates" : "0"
}
}
}
}


What I am trying to do, is save the destination address in the Rider's portion of the Database and then access or read it into the Driver's portion of the database ...

In this case, in the Rider:
I have two ways to get the destination: 
1. search bar (lets just try this one)
2. tap on map
I saved this information to the database:

if (firebaseUser != null) {
mUserId = firebaseUser.getUid();
Log.d(TAG, " my userid = " + mUserId);

// save to firebase...
String.valueOf(destinationCloudEndPoint.child(mUserId).child("Ryydes")
.child("Coordinates")
.child("destination")
.child("searchBar")
.setValue(search_bar_destination));


} else {
Log.d(TAG, "User = null");
}

once it shows up into the database, then I want to be able to retrieve or read into the Driver

private void getSearchBarDestination() { // TODO: Reading SearchBarDest-Data from Rider

DatabaseReference ref = database.getReference();

Log.d(TAG, "getSearchBarDestination: customerId: " + userId);

// TODO: Need userid ... it is null
// Get a reference ...
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference rootRef = database.getReference(Common.user_rider_tbl)
.child(userId)
.child("Ryydes").child("Coordinates")
.child("destination")
.child("searchBar");

// Attach a listener to read the data at our posts reference
rootRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String riderDest = String.valueOf(dataSnapshot.getValue());
etDestination.setText(riderDest);
Log.d(TAG, "riderDest = " + riderDest);
}

@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
}

This is where I am going wrong because I am unable the get the rider's id passed into the driver to access the destination.

What am I doing wrong?

Liz




Reply all
Reply to author
Forward
0 new messages