I have two android apps (A and B) and both have separate projects on Firebase, Currently I am working on a feature which would lets me send messages between app A and app B
You should be able to access the "other" database by explicitly providing the configuration data:
FirebaseOptions options = new FirebaseOptions.Builder()
.setApiKey("AI...j0")
.setApplicationId("1:5...e0") // I'm not certain this is needed
.setDatabaseUrl("https://myapp.firebaseio.com")
.build();
FirebaseApp app = FirebaseApp.initializeApp(getApplicationContext(), options, "app");
FirebaseDatabase database = FirebaseDatabase.getInstance(app);