Welcome back to the blog post series "Build intelligent Android apps" where we take a basic Android app and transform it into a personalized, intelligent, and agentic experience. In our previous post we explored how to build intelligent on-device features using Gemini Nano through ML Kit's Prompt API.
In this post, we will look at how you can leverage Firebase AI Logic to build cloud-hosted and hybrid AI features:
- Grounding answers in real-world context
- Routing requests dynamically between cloud and local execution using hybrid inference
- Translating content with custom routing systems
Sometimes a use case requires AI models with greater world knowledge, a much larger context window, or the ability to handle complex queries. In those scenarios, we can leverage cloud models.
Other times, you want the best of both worlds: using hybrid inference to run on-device when available to lower costs, while falling back to the cloud to ensure compatibility for all devices.
Let’s look at how we implemented three cloud and hybrid features in Jetpacker:
- a museum assistant with web grounding
- hybrid restaurant review drafting
- hotel support chat featuring custom-routed live translation.
Use LLM grounding for up-to-date informationMuseum assistant chatbot with LLM grounding
The Museum assistant is an interactive chatbot designed to help users plan their museum visits. It provides visitors with up-to-date details regarding specific exhibits, current opening hours, ticket pricing, and more.
When building AI features, getting the model to answer with fresh, accurate, and specific real-world information is a common challenge. While cloud models possess massive amounts of world knowledge, they might not know about seasonal exhibits or the current day’s opening hours.
To bridge this gap, we can use grounding techniques to add extra context to the model’s context window. The Firebase AI Logic SDK supports three types of grounding:
- URL grounding: Grounding responses using content from a specific webpage (e.g. current ticket prices or museum rules).
- Google Search grounding: Letting the model query the real-time Google search index for up-to-date details.
- Maps grounding: Using Google Maps location data.
In Jetpacker, we dynamically construct the available tools based on enabled feature flags and initialize the generative model using the Firebase AI SDK:
// implementation("com.google.firebase:firebase-ai-logic")
private var toolList = mutableListOf<Tool>()
init {
if (ENABLE_SEARCH_GROUNDING) {
toolList.add(Tool.googleSearch())
}
if (ENABLE_URL_GROUNDING) {
toolList.add(Tool.urlContext())
}
}
private val generativeModel = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-3-flash",
systemInstruction = content {
text("You are a helpful museum assistant answering questions about a museum. Use plain text.")
},
tools = toolList
)
When the user queries the assistant, if URL grounding is enabled, we append the specific museum resource URLs directly into the prompt:
val groundingText = if (FeatureFlags.ENABLE_URL_GROUNDING) {
"\n If the following message above is about the rules and terms to visit Le Louvre, " +
"if needed answer this urls ${urlList.joinToString()}"
} else {
""
}
val prompt = "$text $groundingText"
var response = chat.sendMessage(prompt)
Hybrid inference: On-device review generation with Maps deep link
Not every AI task requires a cloud-based model, and not every device is online. To help developers balance latency, cost, and offline availability, we recently introduced the Firebase API for Hybrid Inference.
In Jetpacker, the restaurant review feature lets users review select topics and automatically drafts a review. To enable this for all users, we prioritize local execution with Gemini Nano, and fall back to cloud models on devices that don’t support Gemini Nano.
// implementation("com.google.firebase:firebase-ai-logic")
// implementation("com.google.firebase:firebase-ai-ondevice:16.0.0-beta03")
// Initialize the model with hybrid routing configuration
val reviewModel = Firebase.ai.generativeModel(
modelName = "gemini-3.1-flash-lite",
onDeviceConfig = OnDeviceConfig(
inferenceMode = InferenceMode.PREFER_ON_DEVICE
)
)
The Hybrid Inference API supports four distinct routing modes:
- PREFER_ON_DEVICE: Prioritizes local execution and falls back to cloud if Gemini Nano is unavailable.
- PREFER_IN_CLOUD: Prioritizes cloud execution and falls back to on-device if the device goes offline.
- ONLY_ON_DEVICE: Restricts execution strictly to the device.
- ONLY_IN_CLOUD: Restricts execution strictly to the cloud.
Once the review is generated, we copy it to the clipboard and use an intent to open Google Maps directly to the restaurant's review page, providing a seamless user experience:
private fun copyAndOpenMapsReview(context: Context, reviewText: String, placeId: String) {
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("User Review", reviewText)
clipboard.setPrimaryClip(clip)
val uri = Uri.parse("https://search.google.com/local/writereview/mobile?placeid=$placeId")
val intent = Intent(Intent.ACTION_VIEW, uri).apply {
setPackage("com.google.android.apps.maps")
}
context.startActivity(intent)
}
Custom hybrid routing: Hotel support chat translation with simulated personas
The hotel support chat was built to let users finalize logistics and check on hotel details. This feature uses system instructions to configure a localized receptionist assistant. By passing specific information—such as the preferred language and hotel information—in the instructions, we can set up a conversational persona representing a specific hotel.
private val generativeModel = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
systemInstruction = content {
text("""
You are a helpful hotel receptionist at $hotelName only speaking $language.
Answer politely in $language. The bar closes at 10pm and breakfast is from 7am to 10am.
There's someone at the desk 24/7. You can retrieve your luggage from the storage room
at the back of the lobby at any time.
""")
},
modelName = "gemini-3-flash-preview"
)
Because receptionist responses are in the hotel's local language (for example, French for Hotel Le Meurice in Paris), we need to translate messages to the user’s preferred language.
While hybrid models can configure simple routing preferences, complex scenarios require custom routing logic. In Jetpacker, we implement a custom routing stack that takes into account:
- Language identification: Using the on-device ML Kit Language Identification API, we can detect the incoming message language.
- On-device translation (Gemini Nano): ML Kit’s Prompt API lets us translate common language pairs directly on the device, saving bandwidth and cloud cost.
- Cloud translation (Gemini 3 Flash): For more complex languages, we use Gemini Flash 3 to get a higher quality translation.
// implementation("com.google.android.gms:play-services-mlkit-language-id:17.0.0")
// ML Kit for Language Identification (powered by Google Play Services)
private val languageIdentifier = LanguageIdentification.getClient()
// On-device translator model (prefer Gemini Nano) for translating common language pairs
private val hybridTranslationModel = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-3-flash",
onDeviceConfig = OnDeviceConfig(mode = InferenceMode.PREFER_ON_DEVICE)
)
// Cloud translator model for more complex language pairs
private val cloudTranslationModel = Firebase.ai(backend = GenerativeBackend.googleAI())
.generativeModel(
modelName = "gemini-3-flash"
)
When a message needs to be translated, we identify the source language and apply our custom routing logic, executing either on-device or cloud translation:
fun translateMessage(message: SupportChatMessage) {
viewModelScope.launch {
// 1. Detect language using ML Kit Language Identification
val sourceLang = try {
Tasks.await(languageIdentifier.identifyLanguage(message.text))
} catch (e: Exception) {
"Undefined"
}
// 2. Custom routing: we've verified the translation quality for English and Korean with Gemini Nano, and will translate message on-device for those two languages
val routeToCloud = sourceLang != "en" && sourceLang != "kr"
val prompt = "Translate the following text to $selectedLanguage. Just return the translated sentence: ${message.text}."
val (translatedText, routePrefix) = if (routeToCloud) {
val result = cloudTranslationModel.generateContent(prompt)
result.text to "[Cloud]"
} else {
val result = hybridTranslationModel.generateContent(prompt)
result.text to "[On-Device]"
}
if (translatedText != null) {
_translations.update { current ->
current + (message.id to "$routePrefix: $translatedText")
}
}
}
}
In this example, the custom routing logic only takes into consideration the translation’s source and target language. However, based on your app’s use case, you can expand the routing logic to include other factors such as the on-device model version, network connectivity, battery status, and more.
Securing the AI Pipelines: Firebase App Check
Lastly, using AI in the cloud opens up possibilities of API key abuse or unauthorized billing. To secure API calls, we integrated Firebase App Check using both Play Integrity (production) and the local Debug Provider (for local development or emulators).
In the JetPackerApplication.kt file, we install the debug provider at startup and trigger anonymous authentication to establish a secure user session:
// implementation("com.google.firebase:firebase-appcheck-playintegrity")
// implementation("com.google.firebase:firebase-appcheck-debug")
// implementation("com.google.firebase:firebase-auth")
override fun onCreate() {
super.onCreate()
Firebase.initialize(context = this)
Firebase.appCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance()
)
Firebase.auth.signInAnonymously()
}
When building locally on an emulator, App Check prints a local token secret to logcat:
Enter this debug secret into the allow list in the Firebase Console: a8c2dd4c-xxxx-xxxx-xxxx-ef6c114ba27e
Once registered in the Firebase console, local requests are fully verified and authenticated by App Check, protecting our backend while letting us test the app locally.
Conclusion
By combining cloud model capabilities (grounding, system instructions) with on-device capabilities (hybrid routing, translation, security app checks), we created a travel app that is smart, secure, and available offline.
Check out the full source code for Jetpacker on GitHub, and explore the Firebase documentation to get started:
Firebase AI Logic Documentation
Firebase Hybrid Inference API
Learn more
Check out the other parts of this blog post series:
Part 1: Introduction of the app and a high-level overview.
Part 2: On-device intelligence. Deep-dive into ML Kit’s GenAI APIs and Gemini Nano to build privacy-first features like itinerary summarization, receipt parsing, and local audio processing.
Part 3 (this post!): Hybrid and cloud reasoning. Explore how to use Firebase AI Logic to ground LLM answers in real-world data like Google Maps and web context.
Part 4: System integration. Integrating with the Android intelligence system using AppFunctions.
Part 5 (coming soon): In-app agentic workflows. Extend the app with an end-to-end booking assistant powered by A2UI and ADK.
Interested in more on Android Development? Follow Android Developers on YouTube or LinkedIn!
All code snippets in this blog post follow the following copyright notice:
Copyright 2026 Google LLC.
SPDX-License-Identifier: Apache-2.0






