<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aahan Verma on Medium]]></title>
        <description><![CDATA[Stories by Aahan Verma on Medium]]></description>
        <link>https://medium.com/@aahanverma0123?source=rss-ac7371178f90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2WL0UAMq0Y4LsmOZlxfwEg.jpeg</url>
            <title>Stories by Aahan Verma on Medium</title>
            <link>https://medium.com/@aahanverma0123?source=rss-ac7371178f90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:32:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aahanverma0123/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[onNewToken() Is Deprecated. Here's What Actually Replaced It]]></title>
            <link>https://medium.com/@aahanverma0123/onnewtoken-is-deprecated-heres-what-actually-replaced-it-bc300b26bcd7?source=rss-ac7371178f90------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc300b26bcd7</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Aahan Verma]]></dc:creator>
            <pubDate>Thu, 23 Jul 2026 09:17:48 GMT</pubDate>
            <atom:updated>2026-07-23T09:17:48.206Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LmVq63evQhG83kPHzRd17g.png" /><figcaption>onNewToken() is deprecated in favor of Firebase Installation ID (FID) registration</figcaption></figure><p>If you opened an Android project recently and saw this, you’re in the right place:</p><pre>override fun onNewToken(token: String) { }</pre><p>Most of us wrote that override once, years ago, wired it to a sendTokenToServer() call, and never thought about it again. It sat there quietly doing its job through four Android versions.</p><p>It’s deprecated now. And here’s the part that matters: this isn’t a method rename. Firebase is retiring the FCM <strong>registration token</strong> as a concept. The thing you’ve been storing in your users table since FCM launched is on its way out.</p><p>Let me walk through what changed, what replaces it, and — the question I actually care about — whether you should do anything about it today.</p><h3>What changed, on both sides</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bmkGqVdk116p0d4cwn4F3A.png" /><figcaption>An FCM token was a messaging channel; an FID is a device handle tied across the Firebase stack.</figcaption></figure><p>The client moved first. <strong>Android SDK 25.1.0</strong> deprecated three things together:</p><ul><li>FirebaseMessaging.getToken()</li><li>FirebaseMessaging.deleteToken()</li><li>FirebaseMessagingService.onNewToken()</li></ul><p>All three in favour of registration based on the <strong>Firebase Installation ID (FID)</strong>.</p><p>Then the server side landed, and it landed fast. Three Admin SDKs shipped the same change inside ten days:</p><ul><li><strong>Node.js Admin SDK v14.1.0</strong> — June 24, 2026</li><li><strong>Java Admin SDK v9.10.0</strong> — July 2, 2026</li><li><strong>Python Admin SDK v7.5.0</strong> — July 2, 2026</li></ul><p>The release notes are nearly identical across all three: enable fid, deprecate token for the Send API. So Message.token becomes Message.fid, and MulticastMessage.tokens becomes MulticastMessage.fids.</p><p>If you own both the app and the backend, you now have deprecation warnings on both ends of the same pipe</p><h3>The new callback</h3><p>The replacement is a sibling method on the same service class:</p><pre>class MyMessagingService : FirebaseMessagingService() {<br><br>    override fun onRegistered(installationId: String) {<br>        sendRegistrationToServer(installationId)<br>    }<br><br>    override fun onMessageReceived(message: RemoteMessage) {<br>        // unchanged<br>    }<br>}</pre><p>onMessageReceived() is untouched. Only the registration half of the API is moving.</p><p>You also need to opt in via the manifest:</p><pre>&lt;meta-data<br>    android:name=&quot;firebase_messaging_installation_id_enabled&quot;<br>    android:value=&quot;true&quot; /&gt;</pre><p>With that in place, app instances are targeted by FID once registered, and onRegistered() fires with the value.</p><p>One wiring detail that will bite people who disabled auto-init for consent reasons: if auto-initialization is off, nothing triggers registration on its own. You have to ask for it:</p><pre>FirebaseMessaging.getInstance().register()<br>    .addOnCompleteListener { task -&gt;<br>        if (!task.isSuccessful) {<br>            Log.w(TAG, &quot;Registration failed&quot;, task.exception)<br>        }<br>        // onRegistered() will be invoked with the current FID<br>    }</pre><p>Firebase suggests calling this on every app start to guarantee sync status.</p><h3>The FID is not a renamed token</h3><p>This is the part I think most migration posts are going to gloss over, and it’s the part worth slowing down for.</p><p>The FCM registration token was minted by the messaging SDK and scoped to messaging. It existed for one purpose, and if you deleted it, you deleted a messaging credential and nothing else.</p><p>The FID is different in kind. It comes from Firebase Installations — the same installation identifier that Analytics, Remote Config, A/B Testing and In-App Messaging already use. FCM is now issuing and targeting against an identifier that was already threaded through the rest of your Firebase stack.</p><p>Practically, that means the thing you’re about to write into your backend database has a different character than the thing it replaces. A registration token was a messaging-only opaque value. An FID is a handle that correlates this device with your other Firebase product data.</p><p>For a side project, shrug. For anything that went through a privacy or data-handling review — enterprise apps, anything in health or finance, anything with a DPA — that’s a conversation to have with whoever signed off on your original data map. Not a blocker. Just not a silent swap either.</p><h3>Rotation semantics changed, and your cleanup logic might assume otherwise</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VbZ2CJ1blwfrW7GQhD15BQ.png" /></figure><p>Here’s the second thing worth checking in your own codebase.</p><p>Registration tokens rotated for a fairly broad set of reasons, including FCM-side operational ones. If the token encryption key was compromised, FCM could roll new tokens out across every app instance. Your backend had to tolerate churn it didn’t cause and couldn’t predict.</p><p>FIDs change in a narrower and more predictable set of situations:</p><ol><li>The app is restored onto a new device</li><li>The user uninstalls and reinstalls</li><li>The user clears app data</li></ol><p>That’s a tighter, more user-driven set. Which is good — but it means any dedup, staleness or garbage-collection logic you built around <em>token</em> churn was tuned for a different distribution of events. If you have a job that prunes registrations older than N days on the assumption they rotate regularly, that assumption is now weaker. Registrations will live longer and go stale more quietly.</p><h3>Some of your code is now dead</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d0vpqd0cqVNh-J2bJIiD5w.png" /></figure><p>A related win, and my favourite kind of migration outcome: deleting things.</p><p>Plenty of teams built a periodic background job — usually WorkManager — to re-fetch the token and re-upload it to the server, because token freshness was hard to reason about. With the FID APIs, you don’t need that. Under auto-initialization, the SDK handles refreshes and delivers the current FID to onRegistered() during routine syncs on app startup.</p><p>So the shape becomes: implement the callback, upload on every invocation, update your timestamp server-side, and delete the periodic job. Firebase’s own guidance is that client apps don’t need to schedule background work for this anymore.</p><h3>Should you migrate today?</h3><p>Honest answer: <strong>probably not, if you have a working integration.</strong></p><p>Nothing is broken. Both the token and the FID paths are fully supported through this transition, and this is a deprecation, not a removal. Google has said token will go away eventually, but there&#39;s no announced deadline.</p><p>More importantly, the documentation hasn’t caught up. A GitHub issue on the firebase-android-sdk repo — #8316, opened June 17 — points out that getToken() has been deprecated since 25.1.0 while Firebase&#39;s own &quot;send to a specific device&quot; documentation still shows only token-based examples. There&#39;s no FID migration guide sitting next to the deprecation.</p><p>That’s the actual state of things: the client SDK is telling you to move, the Admin SDKs are telling you to move, and the docs for the destination don’t exist yet. Migrating an existing production integration right now means writing against behaviour you can’t look up.</p><p>So my read:</p><ul><li><strong>New integration?</strong> Start on FIDs. You’ll be writing to the field Google has already committed to keeping, and you skip a second migration later.</li><li><strong>Existing integration?</strong> Note it, put it in the backlog, and wait for the migration guide. Don’t rewrite working push infrastructure against undocumented behaviour to silence a warning.</li><li><strong>Either way</strong>, go look at whether you have a periodic token-refresh job, because that one’s worth deleting regardless.</li></ul><p>The strikethrough in your IDE is a real signal. It’s just not an emergency.</p><p><em>If you’re migrating this in a production app, I’d genuinely like to hear how the FID rollout behaved for you — especially around restore-to-new-device, which is the case I’d expect to surface the most surprises.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc300b26bcd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built an AI Agent in Kotlin — And It Changed How I Think About Software]]></title>
            <link>https://medium.com/@aahanverma0123/i-built-an-ai-agent-in-kotlin-and-it-changed-how-i-think-about-software-2e377a03961a?source=rss-ac7371178f90------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e377a03961a</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[google-adk]]></category>
            <category><![CDATA[android-development]]></category>
            <dc:creator><![CDATA[Aahan Verma]]></dc:creator>
            <pubDate>Mon, 01 Jun 2026 16:42:46 GMT</pubDate>
            <atom:updated>2026-06-01T16:42:46.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B-dr0Nd1Hb-Wp0WGYXB1-g.png" /></figure><p>I’ll be honest — when I first heard the term “AI agent,” I rolled my eyes a little.</p><p>It sounded like another buzzword doing the rounds on Twitter, another thing to learn, another framework to evaluate, another hype cycle to wait out.</p><p>But a few weeks ago, I sat down and actually built one. And somewhere between getting it running and watching it maintain context across a conversation, something clicked.</p><p>This is that story.</p><p><strong>GitHub:</strong> <a href="https://github.com/aahanverma00710/adk-chat-agent">https://github.com/aahanverma00710/adk-chat-agent</a></p><h3>A Bit of Background</h3><p>I’ve been building Android apps for over 8 years. I’ve worked with APIs, background services, complex UI systems, payment flows, camera integrations — the full stack of mobile development.</p><p>So when I started exploring AI, I assumed the learning curve would be about prompts. Write better prompts, get better results. Simple enough.</p><p>What I didn’t expect was that the real challenge wasn’t the AI at all. It was the architecture around it.</p><h3>What Even Is an AI Agent?</h3><p>This is the question I kept asking myself at the start, so let me save you the confusion.</p><p>Most of us interact with AI through a simple loop:</p><pre>You type something → Model reads it → Model responds</pre><p>That works fine for answering questions. But it falls apart the moment you need the AI to actually <em>do</em> something — remember what you said five messages ago, call an API, make a decision, coordinate a multi-step task.</p><p>An agent changes that loop entirely:</p><pre>You type something → Agent thinks about it → Uses tools / checks memory / calls APIs → Responds</pre><p>The agent is not just generating text. It’s reasoning. It’s deciding what to do next. It has access to tools and context that a raw LLM call doesn’t have.</p><p>The simplest way I can put it: a chatbot answers questions, an agent solves problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHLvKCEPDtuCcDQibXn19A.png" /></figure><h3>Why Google ADK?</h3><p>When I decided to actually build something, I came across Google’s Agent Development Kit — ADK for short.</p><p>What drew me to it was that it’s built with Kotlin support, it integrates with Gemini, and it’s designed around the idea of agents as proper software components — not just API wrappers.</p><p>It also felt like the right time to explore it. Agent frameworks are still early. Getting hands-on experience now, before everyone else does, felt like a good bet.</p><h3>The Tech Stack</h3><p>Nothing exotic here — just solid, modern Kotlin tooling:</p><p>Layer Technology Language Kotlin 2.2 AI Framework Google ADK 1.3.0 Model Gemini 2.5 Flash Concurrency Kotlin Coroutines 1.8.1 Build Gradle (Kotlin DSL)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aS1EX8whwkhUf25XIPH1qQ.png" /></figure><h3>Getting It Running</h3><p>The setup was straightforward. Clone the repo, add your API key, run it.</p><pre>git clone https://github.com/aahanverma00710/adk-chat-agent.git<br>cd adk-chat-agent</pre><p>Create a local.properties file in the root — this stays out of version control:</p><pre>GOOGLE_API_KEY=your_api_key_here</pre><p>Then just:</p><pre>./gradlew run</pre><p>And you get this in your terminal:</p><pre>=== ADK Chat Agent ===<br>Model : gemini-2.5-flash<br>Type &#39;quit&#39; to exit.</pre><pre>You: Hello!<br>Agent: Hi there! How can I help you today?</pre><p>Honestly, the first time I saw that response come back, it felt underwhelming. Just a chatbot, right?</p><p>Then I started actually using it. And I noticed it remembered things. It built on previous messages. It felt coherent in a way that raw API calls never quite do.</p><p>That’s when I started paying attention.</p><h3>The Part That Actually Surprised Me</h3><h3>Memory is harder than it looks</h3><p>Here’s something that sounds obvious in hindsight: without context management, every message your AI receives is completely isolated.</p><p>You tell it your name. Two messages later, it has no idea who you are.</p><p>ADK handles session management out of the box — conversation history is preserved and threaded through each new request automatically. It’s not magic, but it’s genuinely well-designed. And once you see a conversation that actually <em>flows</em>, you realise how broken most AI interactions feel without it.</p><h3>Kotlin Coroutines fit perfectly here</h3><p>Since every agent response involves a network call to Gemini, blocking the main thread isn’t an option. Coroutines handle this cleanly:</p><pre>suspend fun sendMessage(userInput: String): String {<br>    return withContext(Dispatchers.IO) {<br>        agent.run(userInput)<br>    }<br>}</pre><p>If you’ve used coroutines in Android development, this pattern feels immediately familiar. That made the learning curve much gentler than I expected.</p><h3>Building agents feels like real software engineering</h3><p>This was the biggest surprise.</p><p>I expected AI development to feel… different. More experimental, maybe. Less structured.</p><p>Instead, it felt like building any other complex system — designing components, managing state, thinking about error handling, planning for scale. The AI model is just one piece of the puzzle. The architecture around it is what determines whether the whole thing actually works.</p><h3>What Went Wrong (Because Something Always Does)</h3><p><strong>I hardcoded my API key on day one.</strong> Classic. Switched to local.properties immediately after — but worth mentioning because it&#39;s an easy mistake to make when you just want to see something working.</p><p><strong>The first version blocked the main thread.</strong> Before I added coroutines, the agent would freeze while waiting for Gemini to respond. Not a great experience. Fixing it took about 20 minutes but taught me a lot about how the ADK request lifecycle works.</p><p><strong>I underestimated the project structure.</strong> ADK has opinions about how things should be organised. Ignoring those opinions early on meant refactoring later. Read the docs first. I didn’t. You should.</p><h3>This Is Part 1 of a Series</h3><p>This article is the beginning of a hands-on series where I build a complete AI-powered system from scratch — entirely in Kotlin:</p><ul><li><strong>Part 1</strong> <em>(you are here)</em> — Building an AI Agent in Kotlin with Google ADK</li><li><strong>Part 2</strong> — Exposing the Agent as a REST API with Ktor</li><li><strong>Part 3</strong> — Building a Native Android App Connected to an AI Agent</li></ul><p>By the end of the series, we’ll have a fully working AI agent with a backend server and a native Android front-end.</p><p>Follow me on Medium to get notified when the next parts drop.</p><h3>Final Thoughts</h3><p>I started this project a little sceptical and ended it genuinely excited about where agent-based development is going.</p><p>The shift isn’t from “not knowing AI” to “knowing AI.” It’s from thinking about AI as a feature you bolt on to thinking about it as a core architectural component. That’s a meaningful change in perspective — and one I think every developer is going to have to make eventually.</p><p>If you’re curious about agents, just build something small. Don’t wait until you fully understand the theory. The concepts make sense much faster when you’re working with real code.</p><p><strong>GitHub:</strong> <a href="https://github.com/aahanverma00710/adk-chat-agent">https://github.com/aahanverma00710/adk-chat-agent</a></p><p>Questions, feedback, or thoughts? Drop them in the comments — I read everything.</p><p><em>Aahan Verma is a Senior Android Developer with 8+ years of experience building production mobile applications. Currently exploring the intersection of native Android development and AI-powered systems.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e377a03961a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Production-Ready Android Chat App with Gemini Nano: MVVM, Room, DataStore & On-Device AI]]></title>
            <link>https://medium.com/@aahanverma0123/building-a-production-ready-android-chat-app-with-gemini-nano-mvvm-room-datastore-on-device-ai-ff9077fe3df2?source=rss-ac7371178f90------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff9077fe3df2</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[gemini-nano]]></category>
            <category><![CDATA[google-gemini]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Aahan Verma]]></dc:creator>
            <pubDate>Sat, 30 May 2026 09:14:57 GMT</pubDate>
            <atom:updated>2026-05-30T09:14:57.531Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Production-Ready Android Chat App with Gemini Nano</h3><p>Most Gemini Nano tutorials stop after generating a response from a prompt.</p><p>While that’s useful for understanding the API, it doesn’t show how Gemini Nano fits into a real Android application.</p><p>I wanted to explore something closer to a production-ready implementation: an AI chat application that runs entirely on-device, persists conversations locally, supports chat history, and follows modern Android architecture principles.</p><p>The result was Gemini Nano Chat — an Android application powered by Google’s Gemini Nano model, built using Kotlin, MVVM, Room, DataStore, Coroutines, and Material Design 3.</p><p>Source Code:<br><a href="https://github.com/aahanverma00710/Gemini-Nano-Chat">https://github.com/aahanverma00710/Gemini-Nano-Chat</a></p><h3>Why Gemini Nano?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qtJ35VhjyJmAL5t6yyTG8g.png" /></figure><p>For years, AI-powered applications have relied heavily on cloud infrastructure.</p><p>The traditional flow looks something like this:</p><p>User → API → Server → AI Model → Server → User</p><p>While effective, it introduces several challenges:</p><ul><li>Network dependency</li><li>API costs</li><li>Privacy concerns</li><li>Higher latency</li></ul><p>Gemini Nano changes that approach.</p><p>Instead of sending prompts to a remote server, the model executes directly on supported Android devices.</p><p>This means:</p><ul><li>Lower latency</li><li>Improved privacy</li><li>Offline functionality</li><li>Reduced infrastructure costs</li></ul><p>For mobile developers, this opens up exciting opportunities to build intelligent experiences that remain responsive even without internet connectivity.</p><h3>Project Goal</h3><p>My objective wasn’t simply to call Gemini Nano.</p><p>I wanted to build an application that felt like a complete chat experience.</p><p>The application includes:</p><ul><li>User login</li><li>Persistent chat sessions</li><li>Conversation history</li><li>Local message storage</li><li>Modern chat interface</li><li>On-device AI responses</li><li>Material Design 3 support</li><li>Dark mode compatibility</li></ul><p>Every conversation remains available even after the application is closed because chats and messages are stored locally using Room Database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8kDp1jlcU6Ql0q6QfGgM3A.png" /></figure><h3>Architecture</h3><p>I followed a clean MVVM architecture to separate responsibilities.</p><p>Architecture Flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hAiJjNnG7ys4ZeWLcsNVgQ.png" /></figure><p>The ViewModel handles UI state.</p><p>The Repository acts as the single source of truth.</p><p>Room manages local persistence.</p><p>Gemini Nano is wrapped inside a dedicated helper class that abstracts model initialization and inference.</p><p>This separation made the application significantly easier to maintain and extend.</p><h3>Gemini Nano Integration</h3><p>One of the most interesting parts of the project was handling model availability.</p><p>Unlike traditional API integrations, Gemini Nano may need to be downloaded onto the device.</p><p>To manage this, I created a dedicated NanoHelper class.</p><p>The helper checks whether Gemini Nano is:</p><ul><li>Available</li><li>Downloadable</li><li>Unsupported</li></ul><p>before attempting inference.</p><pre>suspend fun initialize(): Boolean = initMutex.withLock {<br>    if (isSupported != null) return@withLock isSupported!!</pre><pre>    isSupported = try {<br>        when (model.checkStatus()) {<br>            FeatureStatus.AVAILABLE -&gt; {<br>                model.warmup()<br>                true<br>            }</pre><pre>            FeatureStatus.DOWNLOADABLE -&gt; {<br>                var succeeded = false</pre><pre>                model.download().collect { status -&gt;<br>                    when (status) {<br>                        DownloadStatus.DownloadCompleted -&gt;<br>                            succeeded = true<br>                    }<br>                }</pre><pre>                if (succeeded) model.warmup()<br>                succeeded<br>            }</pre><pre>            else -&gt; false<br>        }<br>    } catch (_: Exception) {<br>        false<br>    }</pre><pre>    isSupported!!<br>}</pre><p>This ensures the application gracefully handles different device states before attempting to generate content.</p><h3>Generating Responses</h3><p>Once initialization succeeds, generating content becomes straightforward.</p><pre>suspend fun generateResponse(prompt: String): String {<br>    if (!isReady()) initialize()</pre><pre>    if (!isReady()) {<br>        return &quot;Gemini Nano is not available on this device.&quot;<br>    }</pre><pre>    return try {<br>        model.generateContent(prompt)<br>            .candidates<br>            .firstOrNull()<br>            ?.text<br>            ?: &quot;No response generated.&quot;<br>    } catch (e: Exception) {<br>        &quot;Error: ${e.localizedMessage}&quot;<br>    }<br>}</pre><p>The helper shields the rest of the application from Gemini-specific implementation details.</p><p>As a result, the ViewModel remains focused purely on business logic.</p><h3>Managing Conversations with Room</h3><p>One thing I wanted to avoid was losing conversations whenever the application closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhrtrPPE3x4MYtEbH6O0Ow.png" /></figure><p>To solve this, I introduced two Room entities:</p><h3>ChatEntity</h3><p>Represents an individual conversation.</p><h3>MessageEntity</h3><p>Represents messages belonging to a chat session.</p><p>The relationship looks like:</p><p>Chat<br>├── Message 1<br>├── Message 2<br>├── Message 3<br>└── Message N</p><p>This structure allows users to revisit previous conversations at any time.</p><h3>Building the Chat Experience</h3><p>The ChatViewModel coordinates user interactions and AI responses.</p><p>When a user submits a message:</p><ol><li>User message is stored locally.</li><li>Chat timestamp is updated.</li><li>Gemini Nano generates a response.</li><li>AI response is stored locally.</li><li>UI updates automatically through LiveData.</li></ol><pre>fun sendMessage(content: String) {</pre><pre>    val chatId = _currentChatId.value ?: return</pre><pre>    viewModelScope.launch {</pre><pre>        repository.addUserMessage(chatId, content)</pre><pre>        val response =<br>            nanoHelper.generateResponse(content)</pre><pre>        repository.addAiMessage(<br>            chatId,<br>            response<br>        )<br>    }<br>}</pre><p>Because the UI observes LiveData, messages appear immediately without requiring manual refresh logic.</p><h3>Auto-Generating Chat Titles</h3><p>A small but useful feature is automatic chat naming.</p><p>When a conversation starts, the first user message becomes the chat title.</p><pre>if (_messages.value.isNullOrEmpty()) {<br>    val title =<br>        if (trimmed.length &gt; 40)<br>            trimmed.take(40) + &quot;…&quot;<br>        else<br>            trimmed</pre><pre>    repository.updateChatTitle(<br>        chatId,<br>        title<br>    )<br>}</pre><p>This makes navigating conversation history significantly easier.</p><h3>Persisting User Preferences</h3><p>Instead of SharedPreferences, I used Jetpack DataStore.</p><p>The application remembers:</p><ul><li>Username</li><li>Last opened chat</li><li>User session information</li></ul><p>This provides a cleaner and more modern persistence solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBrO7AEJdM79T5-gkSOrgg.png" /></figure><h3>Challenges I Encountered</h3><h3>1. Device Compatibility</h3><p>Gemini Nano is not available on every Android device.</p><p>The application must always verify model support before initialization.</p><h3>2. Model Download Management</h3><p>Some devices require downloading Gemini Nano before it can be used.</p><p>Handling download states correctly is important for a smooth onboarding experience.</p><h3>3. Maintaining Clean Architecture</h3><p>It’s tempting to call Gemini APIs directly from Activities.</p><p>Encapsulating model operations inside NanoHelper kept the architecture clean and scalable.</p><h3>What I Would Improve Next</h3><p>If I continue developing this project, I’d like to add:</p><ul><li>Streaming responses</li><li>Markdown rendering</li><li>Conversation context memory</li><li>Voice input</li><li>Multimodal support</li><li>Compose UI migration</li><li>AI-generated chat summaries</li></ul><p>These additions would move the application closer to a full-featured AI assistant.</p><h3>Final Thoughts</h3><p>Building with Gemini Nano feels fundamentally different from integrating a traditional cloud-based AI service.</p><p>Instead of thinking about API requests and server infrastructure, the focus shifts toward device capabilities, local storage, and user privacy.</p><p>What impressed me most was how naturally Gemini Nano fit into a modern Android architecture.</p><p>By combining Gemini Nano with MVVM, Room, DataStore, and Material Design 3, it was possible to build a complete AI-powered chat experience that runs directly on the device.</p><p>As on-device AI continues to evolve, I believe we’ll see more Android applications adopting this approach.</p><p>If you’re interested in AI-powered Android development, Gemini Nano is one of the best places to start.</p><p>Source Code:<br><a href="https://github.com/aahanverma00710/Gemini-Nano-Chat">https://github.com/aahanverma00710/Gemini-Nano-Chat</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff9077fe3df2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>