<?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 Nanda Gopal on Medium]]></title>
        <description><![CDATA[Stories by Nanda Gopal on Medium]]></description>
        <link>https://medium.com/@NandagopalR?source=rss-c57c81f7ff3d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EWsXaYZ2uUYNR6pCjxuN1A.png</url>
            <title>Stories by Nanda Gopal on Medium</title>
            <link>https://medium.com/@NandagopalR?source=rss-c57c81f7ff3d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:00:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@NandagopalR/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[MCP vs RAG vs Agents:
What’s the real difference?]]></title>
            <link>https://medium.com/@NandagopalR/mcp-vs-rag-vs-agents-whats-the-real-difference-6187cf7cc323?source=rss-c57c81f7ff3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/6187cf7cc323</guid>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Nanda Gopal]]></dc:creator>
            <pubDate>Sat, 13 Jun 2026 17:13:16 GMT</pubDate>
            <atom:updated>2026-06-13T17:13:16.439Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UyVaQePoXI5bC70EVKw9bA.png" /></figure><p>If you’ve spent any time in AI circles lately, you’ve heard all three: <strong>RAG</strong>, <strong>MCP</strong>, and <strong>Agents</strong>. Startups are building with them. Engineers are debating them. Blog posts are confusing them with each other.</p><p>The confusion is understandable. All three extend what a language model can do. All three involve connecting an LLM to the outside world in some way. But the <em>nature</em> of that connection — what problem it solves, when it fires, and who’s in control — is fundamentally different in each case.</p><p>Let’s cut through the noise.</p><h3>RAG: giving the model a memory it was never trained on</h3><p>Retrieval-Augmented Generation solves one specific problem: <em>the model doesn’t know what it doesn’t know</em>. Training a large language model is expensive and slow. You can’t retrain GPT-4 every time your product documentation changes. RAG is the workaround.</p><p>The idea is deceptively simple. Before the LLM generates a response, you retrieve relevant documents from an external knowledge base — usually a vector database — and inject them into the prompt as context. The model reads those documents and synthesises an answer grounded in them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3wcLH5D4sYiIkzyb4JHYw.png" /></figure><p>There’s no tool-calling happening. No decisions are being made. The LLM is a <em>reader and synthesiser</em>, not an actor. It consumes context and produces text. That’s it.</p><p><em>RAG is about knowledge freshness. It extends what the model knows, not what the model can do.</em></p><h4>What RAG is GREAT for</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7EawE6Gauku6PMxzF2e4Kg.png" /></figure><h4>What RAG cannot do</h4><p>RAG cannot take actions. It cannot browse the web, call an API, write code, or send an email. It can only <em>read</em> what you’ve indexed and <em>write</em> a response. The moment you need the model to <em>do</em> something in the world, RAG alone falls short.</p><h3>MCP: a universal socket for AI tools</h3><p>Model Context Protocol — coined and open-sourced by Anthropic in late 2024 — solves a different problem entirely. The problem isn’t that the model lacks knowledge. It’s that every team integrating an LLM with external tools reinvents the same wheel: authentication, schema definitions, error handling, and capability discovery.</p><p>MCP is a standardised protocol — think of it as <em>USB-C for AI</em>. It defines how a language model host (like Claude, or your custom app) discovers and communicates with external tool servers in a consistent, secure, composable way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5_JkmoU6HhTm3FKJaM6ow.png" /><figcaption>Each MCP server exposes: <strong>tools</strong> (callable functions), <strong>resources</strong> (readable content), and <strong>prompts</strong> (templates)</figcaption></figure><p>MCP isn’t about retrieval. It’s about <em>interoperability</em>. Before MCP, if you wanted Claude to read your Google Drive and write to your Notion, you’d write two completely different integration layers. With MCP, both sides speak the same language — the server declares its capabilities, the host discovers them, and the LLM can invoke them.</p><h4><strong>The key insight about MCP</strong></h4><p>MCP is an <em>infrastructure standard</em>, not an AI technique. It doesn’t make decisions. It doesn’t retrieve knowledge. It defines how tools are packaged and served to an AI system — making it vastly easier to build modular, composable tool ecosystems.</p><h3>What MCP provides</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ezwa7TnQ-ITg9XVhwXf9kA.png" /></figure><p>MCP servers are being built for Asana, Gmail, Salesforce, GitHub, Figma, Linear, and growing. The ecosystem is the point. Your LLM app stops needing to know the implementation details of every service it connects to.</p><h3>Agents: LLMs that reason, plan, and act in loops</h3><p>If RAG is a smarter context window and MCP is a better plug standard, Agents are an entirely different paradigm. An agent doesn’t just respond to a single prompt — it operates in a loop, taking actions, observing results, and deciding what to do next.</p><p>The canonical agent loop looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YR2_sQL8hfg1fAp7HwPvKg.png" /></figure><p>The critical distinction: the model is making autonomous decisions across multiple steps. It decides what tool to call. It interprets the result. It decides whether to continue or stop. This is fundamentally different from a single-shot RAG retrieval, and it’s different from simply having MCP tools available.</p><blockquote><em>An agent is an LLM given the ability to decide what to do next — and then actually do it — without a human in the loop at each step.</em></blockquote><h4>Real agent capabilities</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USjfo3fgg3o9rbGOoJc3Ww.png" /></figure><p>The risks scale, too. An agent with write access to your database, email, or infrastructure can cause cascading failures if it misunderstands a goal. Agent architecture requires careful design of guardrails, sandboxing, and human-in-the-loop checkpoints for high-stakes steps.</p><h3>Side by side: what each one actually does</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u1bGEOsyjFaD3dQg-HzQLQ.png" /></figure><h3>How they work together — not against each other</h3><p>Here’s where most articles miss the point. RAG, MCP, and Agents aren’t competing architectures you must choose between. They are complementary layers in a well-designed AI system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1mdj0I04GeShefXJTypYg.png" /></figure><p>Consider a real-world example: an AI research assistant that can answer questions about your company’s internal documentation <em>and</em> draft tickets in Jira. Here’s how the layers work together:</p><p><strong>User:</strong> “Find the Q4 product specs and create a Jira epic for each unbuilt feature.”</p><p><strong>Agent</strong> decides it needs two things: docs + Jira access. <br>↓<br><strong>RAG</strong> retrieves Q4 spec chunks from the vector DB. <br>↓<br><strong>MCP</strong> (Jira server) receives standardised `create_issue` calls from the agent. ↓<br>The agent loops until all features are ticketed, then reports back.</p><h3>Choosing the right tool for the job</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0mHXDN6bGtv239KBwbvDQ.png" /></figure><h3>The takeaway</h3><p>The terminology fog around RAG, MCP, and Agents isn’t going away — the field moves too fast. But understanding them as solving three distinct problems clears a lot of confusion:</p><p><strong>RAG</strong> answers: <em>What does the model know?</em><br><strong>MCP</strong> answers: <em>How does the model reach external systems?</em><br><strong>Agent&#39;s</strong> answer: <em>How does the model decide what to do?</em></p><p>The strongest AI systems in production use all three. RAG grounds the knowledge. MCP standardises the plumbing. Agents supply the intelligence to drive the loop. Together, they form the architecture of what serious AI engineering looks like in 2025.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6187cf7cc323" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MCP: The Missing Bridge Between AI and the Real World]]></title>
            <link>https://medium.com/@NandagopalR/mcp-the-missing-bridge-between-ai-and-the-real-world-8095b0196500?source=rss-c57c81f7ff3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8095b0196500</guid>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Nanda Gopal]]></dc:creator>
            <pubDate>Thu, 11 Jun 2026 12:04:12 GMT</pubDate>
            <atom:updated>2026-06-11T12:04:12.633Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ok-4DRuXHkffe-JfmxCJAw.png" /><figcaption><em>AI becomes dramatically more useful when it can connect to real tools, real data, and real workflows.</em></figcaption></figure><p>AI models are getting smarter every month. They can write code, summarize documents, reason through complex tasks, and help teams move faster. But there has always been one big limitation:</p><p><strong>AI is only as useful as the context and tools it can access.</strong></p><p>That is where <strong>MCP</strong>, or <strong>Model Context Protocol</strong>, comes in.</p><h3>What Is MCP?</h3><p>MCP stands for <strong>Model Context Protocol</strong>.</p><p>In simple terms, MCP is a standard way for AI systems to connect with external tools and data sources.</p><p>Think of it like a universal adapter. Instead of every AI app building a custom integration for every database, file system, API, CRM, cloud service, or internal tool, MCP provides a shared protocol that lets AI models communicate with these systems in a structured way.</p><p>It helps AI move from:</p><blockquote><em>“I can answer based on what I know.”</em></blockquote><p>to:</p><blockquote><em>“I can inspect your actual environment, understand the context, and help you take action.”</em></blockquote><h3>Why MCP Matters</h3><p>Most companies already have valuable information scattered across many systems: documents, codebases, databases, Slack messages, tickets, APIs, design files, dashboards, and customer records.</p><p>Without access to these systems, AI often gives generic answers.</p><p>With MCP, an AI assistant can securely connect to the right source of truth and provide answers based on real context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIwLoQw22HHv_P19i6oJeg.png" /><figcaption><em>MCP acts as a structured bridge between AI assistants and external systems.</em></figcaption></figure><h3>How MCP Works</h3><p>MCP usually involves three major parts:</p><p><strong>The AI client — </strong>This is the application where the AI assistant runs.</p><p><strong>MCP servers — </strong>These expose specific tools or data sources to the AI, such as a database, file system, GitHub, Slack, or internal API.</p><p><strong>Tools and resources — </strong>These are the actual capabilities the AI can use, such as reading a file, querying a database, searching documentation, or calling an API.</p><p><strong>The key idea is simple:</strong> MCP creates a predictable contract between AI and external systems.</p><h3>Why Developers Should Care</h3><p>For developers, MCP is especially powerful. An MCP-enabled assistant can understand a real codebase instead of guessing from isolated snippets. It can search files, inspect documentation, analyze logs, query APIs, and help debug issues inside the actual development context.</p><p>That changes the workflow.</p><p>Instead of copying code into a chat box, the assistant can work closer to where the problem actually lives.</p><h3>Why Businesses Should Care</h3><p>For businesses, MCP offers a practical path toward useful AI adoption.</p><p>Many companies are not struggling because AI is weak. They are struggling because AI is disconnected from the business context.</p><p>MCP helps solve that.</p><ul><li>A support team could connect AI to knowledge bases and ticket history.</li><li>A sales team could connect AI to CRM data.</li><li>A finance team could connect AI to reports and spreadsheets.</li><li>An engineering team could connect AI to repositories, issue trackers, and deployment systems.</li></ul><p>The result is AI that understands the business, not just the internet.</p><h3><strong>Security Still Matters</strong></h3><p>Connecting AI to tools and data requires care.</p><p>Teams still need to think about permissions, authentication, audit logs, sensitive information, and human approval for important actions.</p><p>The best MCP implementations should follow the principle of least privilege.</p><p>AI should only access what it needs, when it needs it, and with clear visibility into what it is doing.</p><h3>MCP and the Future of AI Agents</h3><p>MCP is important because it supports the next stage of AI: agents. An AI agent is not just a chatbot. It can reason, use tools, perform steps, and complete tasks.</p><p>But agents need context and capabilities.</p><p>Without a protocol like MCP, every agent integration becomes custom and hard to scale. With MCP, developers can build reusable connections between AI systems and real-world tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ok-4DRuXHkffe-JfmxCJAw.png" /><figcaption>The future of AI is not only smarter models, but better connections between models and the systems we use every day.</figcaption></figure><h3>Final Thoughts</h3><p>AI is no longer just about better models.</p><p>The next wave is about better context, better tools, and better integration.</p><p>MCP matters because it helps AI systems become more useful in real environments. It allows AI to understand your actual work, connect to your actual tools, and assist with actual tasks.</p><p>In short:</p><p><strong>MCP is one of the bridges between AI that talks and AI that works.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8095b0196500" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Kotlin Developers Love Sealed Classes for UI States]]></title>
            <link>https://medium.com/@NandagopalR/why-kotlin-developers-love-sealed-classes-for-ui-states-3ea219505176?source=rss-c57c81f7ff3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ea219505176</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-sealed-class]]></category>
            <dc:creator><![CDATA[Nanda Gopal]]></dc:creator>
            <pubDate>Wed, 10 Jun 2026 12:18:36 GMT</pubDate>
            <atom:updated>2026-06-10T12:18:36.615Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TKErhQv5jZKaRp6lNXEaWQ.png" /></figure><p>If you have built Android apps for a while, you have probably written UI code that looks like this:</p><pre>if (isLoading) {<br>    showLoading()<br>} else if (error != null) {<br>    showError(error)<br>} else if (data != null) {<br>    showContent(data)<br>}</pre><p>At first, this feels fine.</p><p>Then the screen grows. You add empty states, Retry states, Pagination, Offline mode, Validation errors, and Partial content. Suddenly, your UI state is scattered across multiple booleans and nullable values.</p><p>That is where Kotlin sealed classes feel almost magical.</p><p>They let you model UI state as a clear, limited set of possibilities.</p><p>Instead of asking, “Which combination of flags is currently true?”, your code asks a better question:</p><blockquote><em>“What state is the screen in right now?”</em></blockquote><h3>The Problem with Boolean-Based UI State</h3><p>A common beginner approach is to represent UI state like this:</p><pre>data class UserUiState(<br>    val isLoading: Boolean = false,<br>    val user: User? = null,<br>    val errorMessage: String? = null<br>)</pre><p>This works, but it allows impossible states.</p><p>For example:</p><pre>UserUiState(<br>    isLoading = true,<br>    user = User(&quot;Alex&quot;),<br>    errorMessage = &quot;Something went wrong&quot;<br>)</pre><p>Is the screen loading? Did it succeed? Did it fail?</p><p>The data structure is unknown. It allows all three at once.</p><p>That means every Composable, Fragment, or View has to interpret the state and hope everyone follows the same rules.</p><p>Sealed classes solve this by making invalid states impossible.</p><h3>What Is a Sealed Class?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQ5y23D_nrbE5Mi1WwKvuw.png" /></figure><p>A sealed class in Kotlin represents a restricted hierarchy. In simple terms, it lets you define a fixed set of types that belong together.</p><pre>sealed class UserUiState {<br>    data object Loading : UserUiState()<br>    data class Success(val user: User) : UserUiState()<br>    data class Error(val message: String) : UserUiState()<br>}</pre><p>Now the UI can only be in one of these states:</p><ul><li><strong>Loading</strong></li><li><strong>Success</strong></li><li><strong>Error</strong></li></ul><p>No weird combinations. No guessing. No nullable maze.</p><h3>Why This Feels So Good in UI Code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLmswPj-enjGNyNlM04Sgw.png" /></figure><p>The biggest win is clarity.</p><p>Your UI rendering becomes direct and readable:</p><pre>@Composable<br>fun UserScreen(uiState: UserUiState) {<br>    when (uiState) {<br>        is UserUiState.Loading -&gt; {<br>            LoadingView()<br>        }<br><br>        is UserUiState.Success -&gt; {<br>            UserProfile(user = uiState.user)<br>        }<br><br>        is UserUiState.Error -&gt; {<br>            ErrorView(message = uiState.message)<br>        }<br>    }<br>}</pre><p>This reads almost like a product spec:</p><ul><li>When loading, show loading.</li><li>When successful, show profile.</li><li>When it fails, show an error.</li></ul><p>That is exactly how UI state should feel.</p><h3>Exhaustive when Is the Secret Sauce</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SrZ4pZc2WeR-2zEKdUYKaw.png" /></figure><p>One of the best parts of sealed classes is that Kotlin understands all possible subclasses.</p><p>So if you later add a new state:</p><pre>data object Empty : UserUiState()</pre><p>Kotlin can warn you that your <strong>when</strong> expression does not yet handle it.</p><pre>when (uiState) {<br>    is UserUiState.Loading -&gt; LoadingView()<br>    is UserUiState.Success -&gt; UserProfile(uiState.user)<br>    is UserUiState.Error -&gt; ErrorView(uiState.message)<br>    // Kotlin reminds you: what about Empty?<br>}</pre><p>That compiler feedback is huge.</p><p>Instead of discovering missing UI states through QA or user reports, you catch them while writing code.</p><h3>Perfect Fit for ViewModel State</h3><p>Sealed classes pair beautifully with <strong>StateFlow</strong>.</p><pre>class UserViewModel(<br>    private val repository: UserRepository<br>) : ViewModel() {<br><br>    private val _uiState =<br>        MutableStateFlow&lt;UserUiState&gt;(UserUiState.Loading)<br><br>    val uiState: StateFlow&lt;UserUiState&gt; = _uiState<br><br>    fun loadUser() {<br>        viewModelScope.launch {<br>            _uiState.value = UserUiState.Loading<br><br>            try {<br>                val user = repository.getUser()<br>                _uiState.value = UserUiState.Success(user)<br>            } catch (e: Exception) {<br>                _uiState.value = UserUiState.Error(<br>                    e.message ?: &quot;Something went wrong&quot;<br>                )<br>            }<br>        }<br>    }<br>}</pre><p>And in Jetpack Compose:</p><pre>@Composable<br>fun UserRoute(viewModel: UserViewModel) {<br>    val uiState by viewModel.uiState.collectAsStateWithLifecycle()<br><br>    UserScreen(uiState = uiState)<br>}</pre><p>Clean ViewModel. Clean UI. A clear contract between them.</p><pre>@Composable<br>fun UserRoute(viewModel: UserViewModel) {<br>    val uiState by viewModel.uiState.collectAsStateWithLifecycle()<br><br>    UserScreen(uiState = uiState)<br>}</pre><h3>Sealed Interfaces Work Too</h3><p>In modern Kotlin, you may also see sealed interfaces:</p><pre>sealed interface UserUiState {<br>    data object Loading : UserUiState<br>    data class Success(val user: User) : UserUiState<br>    data class Error(val message: String) : UserUiState<br>}</pre><p>For many UI state cases, sealed interfaces and sealed classes both work well.</p><p>Use a sealed class when you want shared constructor state or common behavior. Use a sealed interface when you want a closed set of possible types.</p><p>For UI state, sealed interfaces are often a nice, lightweight choice.</p><h3>A More Realistic UI State</h3><p>Real screens usually need more than loading, success, and error.</p><p>For example:</p><pre>sealed interface ArticlesUiState {<br>    data object Loading : ArticlesUiState<br><br>    data object Empty : ArticlesUiState<br><br>    data class Success(<br>        val articles: List&lt;Article&gt;,<br>        val isRefreshing: Boolean = false<br>    ) : ArticlesUiState<br><br>    data class Error(<br>        val message: String,<br>        val canRetry: Boolean = true<br>    ) : ArticlesUiState<br>}</pre><p>This is expressive without becoming chaotic.</p><p>The screen can clearly represent:</p><ul><li>Initial loading</li><li>Empty result</li><li>Loaded content</li><li>Refreshing existing content</li><li>Error with retry behavior</li></ul><p>The important part is that each state has only the data it needs.</p><h3>Why Developers Prefer This Pattern</h3><p>Kotlin developers love sealed classes for UI states because they give you:</p><ol><li>Type safety — The compiler understands your UI states.</li></ol><p>2. Better readability — State rendering becomes simple and declarative.</p><p>3. Fewer invalid states — You avoid confusing combinations of booleans and nullable fields.</p><p>4. Easier refactoring — Add a new state, and Kotlin helps you update the affected UI.</p><p>5. Better Compose compatibility — Compose works best when UI is a function of state, and sealed classes model that state beautifully.</p><h3>When Not to Use Sealed Classes</h3><p>Sealed classes are great, but they are not required everywhere. For very small UI pieces, a simple data class may be enough:</p><pre>data class SearchUiState(<br>    val query: String = &quot;&quot;,<br>    val results: List&lt;Result&gt; = emptyList()<br>)</pre><p>If your state is mostly continuous data, use a data class.</p><p>If your screen has distinct modes, such as loading, success, empty, and error, sealed classes are usually a better fit.</p><h3>Final Thoughts</h3><p>Sealed classes make UI state feel intentional.</p><p>They help you move from fragile combinations of states to a clear model of what the screen can actually be. That is why Kotlin developers reach for them again and again, especially in Android apps using ViewModels, StateFlow, and Jetpack Compose.</p><p>A good UI state model does not just make the code cleaner.</p><p>It makes the screen easier to reason about.</p><p>And in real-world apps, that is a very big deal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ea219505176" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Life vs Kotlin Life]]></title>
            <link>https://blog.tarkalabs.com/java-life-vs-kotlin-life-4007ba159521?source=rss-c57c81f7ff3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4007ba159521</guid>
            <category><![CDATA[comparison]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Nanda Gopal]]></dc:creator>
            <pubDate>Thu, 29 Sep 2022 10:29:28 GMT</pubDate>
            <atom:updated>2023-05-02T19:13:53.996Z</atom:updated>
            <content:encoded><![CDATA[<p>Kotlin provides many amazing and powerful features over Java. Developers always love clean and concise code. Less code takes less time to write and less time to read and makes it easy to maintain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pqAo-y89hkGjG1obChMW_g.png" /><figcaption>Image Credit: <a href="https://medium.com/u/27bc603427b">Gaurav Singh</a></figcaption></figure><p>Kotlin has concise code compared to Java. It drastically reduces the amount of boilerplate code, increasing your development’s speed. Kotlin simplifies the developer’s life with its powerful features. We’ll see how in this blog by diving into Kotlin’s features.</p><h4><strong>Why this blog?</strong></h4><p>Before Kotlin was introduced, Java was the only language to develop Native android applications. Nowadays, most developers are loving &amp; using Kotlin. But, many of them use Kotlin, like how they’ve used Java. They’re still living Java life, even while using Kotlin. This blog post is to help bring them into Kotlin Life and use it to its fullest potential.</p><h3>Kotlin features over Java:</h3><p>We’re going to see all the examples from this class.</p><pre>public class Developer {<br>  private long developerId; // Primary Key  <br>  private String name;<br>  private String designation;<br>  private Platform platform;<br>  private Date joinedAt;<br>  private String address;</pre><pre>  enum Platform {<br>    <em>ANDROID</em>,<br>    <em>IOS<br>  </em>}<br>// Getters and Setters<br>}</pre><h4>1. Filtering a list and returning another list:</h4><p>Let’s say we have a <strong>List&lt;Developer&gt;</strong> and we need to get all the Developers whose platform is <strong>Android</strong>.</p><p><strong>Using Java:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c53ebeaedd203f9db9b9ffda19fa63fe/href">https://medium.com/media/c53ebeaedd203f9db9b9ffda19fa63fe/href</a></iframe><p><strong>Using Kotlin</strong> (<strong><em>filter</em></strong> Operator):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72bc919c272d1c5555f81d7d205e3158/href">https://medium.com/media/72bc919c272d1c5555f81d7d205e3158/href</a></iframe><p>2. Converting a list into another:</p><p>Let’s say we have a <strong>List&lt;Developer&gt;</strong> and we need to get all the Developer&#39;s names alone.</p><p>Using Java:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb240bd8ebb52138b321655486de4bee/href">https://medium.com/media/cb240bd8ebb52138b321655486de4bee/href</a></iframe><p><strong>Using Kotlin</strong> (<strong><em>map</em></strong><em> &amp; </em><strong><em>mapNotNull </em></strong>Operator):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0398a832eed9c7dca9043a18cb72591/href">https://medium.com/media/a0398a832eed9c7dca9043a18cb72591/href</a></iframe><h4>3. Find an element in a list:</h4><p>Let’s say we have a <strong>List&lt;Developer&gt;</strong> and we need to find a Developer whose name is John. Query = “John”.</p><p>Using Java:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37ba6f27d4a9ffb76d4d4a193617fc8f/href">https://medium.com/media/37ba6f27d4a9ffb76d4d4a193617fc8f/href</a></iframe><p>Using Kotlin: (<strong><em>find</em></strong> Operator)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d82bae5fe971455566f37684f582efb9/href">https://medium.com/media/d82bae5fe971455566f37684f582efb9/href</a></iframe><h4>4. Partitioning a list into 2 by a condition:</h4><p>Let’s say we have a <strong>List&lt;Developer&gt;</strong> with only the <strong>Android</strong> and <strong>iOS</strong> categories. We have to partition them into 2. Like, as Android Devs and iOS Devs. Please have a look at my repo for the differences.</p><p><a href="https://github.com/NandagopalR/Java_Life_vs_Kotlin_Life">GitHub - NandagopalR/Java_Life_vs_Kotlin_Life</a></p><h4>5. Working with Database or InputStreams or Read or Write a file:</h4><p>Let’s say you’re working with InputStreams to read or write a file or save data into any mobile database. After completing any actions with the above case, you need to close the InputStreams and database instances. So, every time you need to do like,</p><pre>fileOutputStream.close(); // For <strong>FileOutputStream</strong><br>zipInputStream.close(); // For <strong>ZipInputStream</strong><br>realm.close(); // For <strong>Realm Database </strong>and<strong> Other Databases</strong></pre><p>Using Kotlin: (<strong><em>use</em></strong> Operator — I really love this operator specifically ). For the differences, please have a look at my repo.</p><p><a href="https://github.com/NandagopalR/Java_Life_vs_Kotlin_Life">GitHub - NandagopalR/Java_Life_vs_Kotlin_Life</a></p><h4>6. GroupBy a list by Dev’s Designation</h4><p>Let’s say we have a <strong>List&lt;Developer&gt; </strong>and we want to map them by their designation. Please have a look at my repo for the differences.</p><p><a href="https://github.com/NandagopalR/Java_Life_vs_Kotlin_Life">GitHub - NandagopalR/Java_Life_vs_Kotlin_Life</a></p><h4>7. Mapping a list by Dev’s Id</h4><p>Let’s say we have a <strong>List&lt;Developer&gt; </strong>and we want to map them by their designation.</p><p><a href="https://github.com/NandagopalR/Java_Life_vs_Kotlin_Life">GitHub - NandagopalR/Java_Life_vs_Kotlin_Life</a></p><h3><strong>Conclusion:</strong></h3><p>I have mentioned simpler ways in Java, but there are many ways to accomplish the same action. Also, In Kotlin many operators are there to save our life. Please feel free to comment if anything I missed. Part II will be available soon with <a href="https://github.com/NandagopalR/Java_Life_vs_Kotlin_Life"><strong>Coroutine</strong></a>, <strong>ktor,</strong> and other essential features.</p><blockquote>Hi! I’m Nandagopal, a resident mobile developer @ <a href="http://www.tarkalabs.com/">TarkaLabs</a> where I develop innovative products that simplify Human life and create transformative solutions. Let’s Connect!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4007ba159521" width="1" height="1" alt=""><hr><p><a href="https://blog.tarkalabs.com/java-life-vs-kotlin-life-4007ba159521">Java Life vs Kotlin Life</a> was originally published in <a href="https://blog.tarkalabs.com/">Tarka Labs Blogs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Google Play Billing into an Android Application]]></title>
            <link>https://medium.com/@NandagopalR/integrating-google-play-billing-into-an-android-application-b6eb6af176a7?source=rss-c57c81f7ff3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6eb6af176a7</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[in-app-purchase]]></category>
            <category><![CDATA[in-apps]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[google-play-billing]]></category>
            <dc:creator><![CDATA[Nanda Gopal]]></dc:creator>
            <pubDate>Mon, 13 Jan 2020 12:54:39 GMT</pubDate>
            <atom:updated>2020-01-13T12:54:39.803Z</atom:updated>
            <content:encoded><![CDATA[<p>As my first story in <a href="https://medium.com/">Medium</a> that, I decided to explain about Google Play Billing (In-app Billing), Play console setup and its features and implementations in Android application. In this blog, I am going to explain one of the In-App product type <strong>One-Time Product. </strong>Before we directly dive into <strong>One-Time Product, </strong>let me describe What is In-App Billing and how it works.</p><h4>What is In-app Billing?</h4><p>Google Play Billing is a Google service that lets you sell digital content from your android application. You can use the Google service to sell a wide range of content, including downloadable content such as media files or photos, virtual content like game levels, premium plans and app features and many more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5gn_e0Cjpp3vy-kv2cFRA.png" /><figcaption>In-app dialog with Digital Content</figcaption></figure><h4>What is Digital Content?</h4><p>If you are playing a Car game, then you need fuel to play/continue your game in all the levels. Here, the fuel isn’t a physical product. So, If you don’t have a chance to collect the fuel, then you have to buy the fuel by using your Google digital wallet or Credit card. So we can call the fuel as Digital content.</p><p><strong>Reference: </strong><a href="https://developer.android.com/google/play/billing/billing_overview">https://developer.android.com/google/play/billing/billing_overview</a></p><h4>In-App Product Types:</h4><p>Google Play Billing can be used to sell the following types of in-app products:</p><ul><li><strong>One-time products:</strong> An in-app product requiring a single, non-recurring charge to the user’s form of payment. Additional game levels, premium loot boxes, and media files are examples of one-time products. The Google Play Console refers to one-time products as <em>managed products</em>, and the Google Play Billing library calls them “INAPP”.</li><li><strong>Rewarded products:</strong> An in-app product requiring the user to watch a video advertisement. Extra lives, in-game currency, and quick completion of timed tasks are examples of rewarded products. The Google Play Console refers to rewarded products as <em>rewarded products</em>, and the Google Play Billing Library calls them “INAPP”.</li><li><strong>Subscriptions:</strong> An in-app product requiring a recurring charge to the user’s form of payment. Online magazines and music streaming services are examples of subscriptions. The Google Play Billing Library calls these “SUBS”.</li></ul><h4>Process flow of In-App Product Billing:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*n_Nl_gJY6raolIUtxIkT2g.png" /></figure><p>So, this is what In-App Billing is. We are now ready to set up the <strong>One-time product</strong> and implement its functionalities into the Android application by having prerequisites and following the steps,</p><h3>Prerequisites:</h3><ul><li>Android Studio,</li><li>Google play console account.</li></ul><h3>Steps to do:</h3><p><strong>Step 1:</strong> Create a new application in Android Studio,</p><p><strong>Step 2:</strong> Create an application and fill Store listing in <a href="https://play.google.com/apps/publish/">Google play console</a>,</p><p><strong>Step 3:</strong> Create a One-Time Product in <a href="https://play.google.com/apps/publish/">Google play console</a>,</p><p><strong>Step 4:</strong> Integrate Billing dependancy into <strong>Gradle</strong> build system &amp; Handle purchases,</p><p><strong>Step 5:</strong> Publish &amp; test the application.</p><h3>Step 1: Create a new application in Android Studio</h3><ul><li><em>Launch Android studio </em><strong><em>-&gt;</em></strong><em> Open File menu</em><strong><em>-&gt; </em></strong><em>New</em><strong><em> -&gt; </em></strong><em>New Project -&gt; Select Empty Activity and click Next.</em></li><li><em>Select </em><strong><em>Kotlin</em></strong><em> as your preferred language and click </em><strong><em>Finish</em></strong><em>.</em></li></ul><h3>Step 2: Play Console set up</h3><p>Now Let’s set up the products in our <strong><em>play console</em></strong>.</p><ul><li>First, login into Play console and then click <strong>Create Application.</strong></li><li>Set up your app like providing App name, Title, Short and Long description, Graphic assets, Promo video, Application type and category.</li><li>Once done, Finish all the information like <em>Content rating</em>, <em>Pricing</em> &amp; <em>distribution</em> and reach to point where you just need to upload the APK file.</li></ul><blockquote><strong>Important:</strong> To continue <em>Content rating</em>, <em>Pricing</em> &amp; <em>distribution</em> or create In-App products, you have to publish at least one APK. So, build a release APK and publish that as a <strong>Beta version</strong> into <strong>Google play console</strong> to go further.</blockquote><h3>Step 3: Create a One-Time Product</h3><p>After you’ve published your APK and once you filled <em>Content rating</em>, <em>Pricing</em> &amp; <em>distribution, just do the following,</em></p><blockquote>From the left menu, open <strong>Store Presence -&gt; In-app products -&gt; Managed products</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wMmIHdocC9T_KQMhbO5nAw.png" /><figcaption>Managed products view</figcaption></figure><p>Here, we can see the list of one-time products of our application.</p><blockquote>Now, click <strong>CREATE MANAGED PRODUCT</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99Qz1dEZxcbqXs39oXb5mw.png" /></figure><p>Here, we can create a one-time product.</p><blockquote>In <strong>Managed Products</strong>, we can <strong>Edit</strong> or <strong>Delete</strong> the product if we don’t want at any point of time.</blockquote><blockquote>But, In <strong>Subscription</strong> products, we <strong>cannot</strong> <strong>Delete</strong> the product anymore. Once the product created, we cannot undo or delete or remove from the list.</blockquote><p>Here, the <strong><em>Product ID</em></strong> is unique for all products in the Managed Product list and this is what we have to play within our code. In Code, this id will be returned in the name of <strong><em>SKU.</em></strong></p><blockquote>Set up your first product by providing <strong>Product ID</strong>, <strong>Title</strong>, <strong>Description</strong> and <strong>Pricing details</strong> for various countries.</blockquote><p>Now that, we have successfully created a One-Time product in google play console. Let’s do code to purchase the products from google play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HTrNGPuHex44PjpYlzNwWg.png" /><figcaption>Sample Managed Products list</figcaption></figure><h3>Step 4: Integrate Billing &amp; Handle In-App Purchase</h3><p>Now that, we have successfully created a One-Time product in google play console. Let’s do code to purchase the products from google play.</p><blockquote>Add the following line into the <strong>dependencies</strong> section in your <strong>build.gradle</strong> (app level) of your app,</blockquote><pre><strong>build.gradle (App Level)</strong><br>dependencies {</pre><pre>...</pre><pre>implementation &#39;com.android.billingclient:billing:2.1.0&#39;<br>implementation &#39;com.android.billingclient:billing-ktx:2.1.0&#39;</pre><pre>}</pre><p>In <strong>Manifest:</strong></p><p>Add the below permissions in your Manifest file.</p><pre>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;<br>&lt;uses-permission android:name=&quot;com.android.vending.BILLING&quot; /&gt;</pre><p>Do code to implement Billing Client in your <strong>HomeActivity.kt</strong></p><pre><em>// Declare billingClient variable</em><br>private lateinit var billingClient: BillingClient</pre><blockquote><em>in onCreate() method,</em></blockquote><ul><li>Call <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#newBuilder(android.content.Context)">newBuilder()</a> to create an instance of <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient">BillingClient</a> You must also call <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#setListener(com.android.billingclient.api.PurchasesUpdatedListener)">setListener()</a>, passing a reference to a <a href="https://developer.android.com/reference/com/android/billingclient/api/PurchasesUpdatedListener">PurchasesUpdatedListener</a> to receive updates on purchases initiated by your app, as well as those initiated by the Google Play Store.</li></ul><pre>billingClient = BillingClient.newBuilder(this)<br>.enablePendingPurchases()<br>.setListener(this)<br>.build()</pre><blockquote>By adding <strong>.enablePendingPurchases() </strong>with <strong>billingClient</strong>, we can query the purchased items from google play.</blockquote><p><strong>Connect to Google Play: </strong>Before you can make Google Play Billing requests, you must first establish a connection to Google Play by doing the following:</p><ol><li>Establish a connection to Google Play. The setup process is asynchronous, and you must implement a <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClientStateListener">BillingClientStateListener</a> to receive callback once the setup of the client is complete and it’s ready to make further requests.</li><li>Override the <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClientStateListener#onBillingServiceDisconnected()">onBillingServiceDisconnected()</a> callback method and implement your own retry policy to handle lost connections to Google Play in the event the client loses connection. For example, the BillingClient may lose the connection if the Google Play Store service is updating in the background. The BillingClient must call the <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#startConnection(com.android.billingclient.api.BillingClientStateListener)">startConnection()</a> method to restart the connection before making further requests.</li></ol><p>The following code sample demonstrates how to start a connection and test that it’s ready to use:</p><pre>billingClient.startConnection(object : BillingClientStateListener <br>{<br>override <br>fun onBillingSetupFinished(billingResult: BillingResult) <br>{<br>if (billingResult.<em>responseCode </em>== BillingClient.BillingResponseCode.<em>OK</em>) <br>  {<br>   // The BillingClient is ready. You can query purchases here.<br>   queryInventoryAsync(); // This is used to fetch purchased items from google play store<br>  }<br>}</pre><pre>override fun onBillingServiceDisconnected() <br>  {<br>   // Try to restart the connection on the next request to<br>   // Google Play by calling the startConnection() method.<br>   showToast(&quot;Billing service disconnected...&quot;)<br>  }<br>}<br>)</pre><h3>Query for in-app product details:</h3><ul><li>The unique product IDs you created when configuring your in-app products are used to asynchronously query Google Play for in-app product details.</li><li>To query Google Play for in-app product details, call <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#querySkuDetailsAsync(com.android.billingclient.api.SkuDetailsParams,%20com.android.billingclient.api.SkuDetailsResponseListener)">querySkuDetailsAsync()</a>. When calling this method, pass an instance of <a href="https://developer.android.com/reference/com/android/billingclient/api/SkuDetailsParams">SkuDetailsParams</a> that specifies a list of product ID strings and a SkuType. The SkuType can be either SkuType.INAPP for one-time products or rewarded products or SkuType.SUBS for subscriptions</li></ul><pre>List&lt;String&gt; productIdsList = new ArrayList&lt;&gt; ();<br>productIdsList.add(&quot;com.nanda.inappbilling.o57jdsb9j8&quot;);<br>productIdsList.add(&quot;com.nanda.inappbilling.4skfhbshjf&quot;);</pre><pre>val params = SkuDetailsParams.newBuilder()<br>params.setSkusList(productIdsList)<br>.setType(BillingClient.SkuType.<em>INAPP</em>)</pre><pre>billingClient.querySkuDetailsAsync(params.build(),<br>    (billingResult, skuDetailsList) -&gt; {</pre><pre>// Do your code here</pre><pre>});</pre><blockquote>In above, <strong><em>skuList </em></strong><em>contains will have all the unique id’s of our managed product.</em></blockquote><p><strong>Query most recent purchases:</strong></p><ul><li>The <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#queryPurchases(java.lang.String)">queryPurchases()</a> method uses a cache of the Google Play Store app without initiating a network request. If you need to check the most recent purchase made by the user for each product ID, you can use <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#queryPurchaseHistoryAsync(java.lang.String,%20com.android.billingclient.api.PurchaseHistoryResponseListener)">queryPurchaseHistoryAsync()</a>, passing the purchase type and a <a href="https://developer.android.com/reference/com/android/billingclient/api/PurchaseHistoryResponseListener">PurchaseHistoryResponseListener</a> to handle the query result.</li><li><a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#queryPurchaseHistoryAsync(java.lang.String,%20com.android.billingclient.api.PurchaseHistoryResponseListener)">queryPurchaseHistoryAsync()</a> returns a <a href="https://developer.android.com/reference/com/android/billingclient/api/PurchaseHistory">PurchaseHistory</a> object that contains info about the most recent purchase made by the user for each product ID, even if that purchase is expired, canceled, or consumed. Use <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#queryPurchases(java.lang.String)">queryPurchases()</a> whenever possible, as it uses the local cache, instead of queryPurchaseHistoryAsync(). If using queryPurchaseHistoryAsync(), you can also combine it with a <strong>Refresh</strong> button, allowing users to update their list of purchases.</li></ul><pre>override fun onPurchaseHistoryResponse(<br>    billingResult: BillingResult?,<br>    purchaseHistoryList: MutableList&lt;PurchaseHistoryRecord&gt;?<br>) {<br>    if (billingResult?.<em>responseCode </em>== BillingClient.BillingResponseCode.<em>OK</em>) {<br>        if (!JavaUtils.isNullOrEmpty(purchaseHistoryList)) {<br>            for (purchase in purchaseHistoryList) {<br>                // Do your code to handle purchased items here<br>            }<br>        }<br>    }<br>    adapter.setBookList(booksList)<br>}</pre><blockquote><em>This is where we have to add our conditions to check the items are already purchased or not. If the </em><strong><em>purchaseRecordList </em></strong><em>doesn’t have data then there’s no items purchased yet.</em></blockquote><p><strong>Do In-App:</strong></p><ul><li>Some Android phones might have an older version of the Google Play Store app that doesn’t support certain product types, such as subscriptions. Therefore, before your app enters the billing flow, call <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#isFeatureSupported(java.lang.String)">isFeatureSupported()</a> to check that the device supports the products you want to sell. For a list of product types, see <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient.FeatureType">BillingClient.FeatureType</a>.</li><li>To start a purchase request from your app, call the <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingClient#launchBillingFlow(android.app.Activity,%20com.android.billingclient.api.BillingFlowParams)">launchBillingFlow()</a> method from the UI thread. Pass a reference to a <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams">BillingFlowParams</a> object containing the relevant data to complete the purchase, such as the product ID (skuId) of the item and product type (SkuType.INAPP for a one-time product or rewarded product, or SkuType.SUBS for a subscription). To get an instance of <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams">BillingFlowParams</a> , use the <a href="https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder">BillingFlowParams.Builder</a> class:</li></ul><pre>val flowParams = BillingFlowParams.newBuilder()<br>    .setSkuDetails(model.skuDetail)<br>    .build()<br>billingClient.launchBillingFlow(this, flowParams)</pre><blockquote><strong><em>model.getSkuDetails()</em></strong> returns the SkuDetils data of the particular product which we’ve got from <strong><em>querySkuDetailsAsync() </em></strong><em>method.</em></blockquote><p>Also, once the user clicks the purchase button the <strong><em>billingClient</em></strong> will give the result that, the user purchased the product or canceled the process or something. We can get those kinds of results from <strong><em>onPurchasesUpdated() </em></strong><em>method. We have to handle purchase-related conditions on that method itself,</em></p><pre>override fun onPurchasesUpdated(<br>    billingResult: BillingResult?,<br>    purchaseList: MutableList&lt;Purchase&gt;?<br>) {<br>    if (billingResult?.<em>responseCode </em>== BillingClient.BillingResponseCode.<em>OK</em>) {<br>        for (purchase in purchaseList!!) {<br>            acknowledgePurchase(purchase.<em>purchaseToken</em>)<br>        }<br>    } else if (billingResult?.<em>responseCode </em>== BillingClient.BillingResponseCode.<em>USER_CANCELED</em>) {<br>        // Handle an error caused by a user cancelling the purchase flow.<br>    } else {<br>        // Handle any other error codes.<br>    }<br>}</pre><h3>Acknowledge a purchase:</h3><pre>private fun acknowledgePurchase(purchaseToken: String) {<br>    val params = AcknowledgePurchaseParams.newBuilder()<br>        .setPurchaseToken(purchaseToken)<br>        .build()<br>    billingClient.acknowledgePurchase(params) <strong>{ </strong>billingResult <strong>-&gt;<br>        </strong>if (billingResult.<em>responseCode </em>== BillingClient.BillingResponseCode.<em>OK</em>) {<br>            val debugMessage = billingResult.<em>debugMessage<br>            </em>showToast(debugMessage)<br>        }<br>    <strong>}<br></strong>}</pre><h3>Step 4: Publish &amp; Test the application</h3><p>Now, we are done with <strong><em>BillingClient </em></strong><em>and handling </em><strong><em>Purchase. </em></strong>Just generate a Signed APK and upload it to the Google Play Console and wait for the app to get accepted from Google.</p><p>Now, click on one item. that’ll prompt a bottom dialog like below,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXjkN6Xl-6l_Wz2DC4Z9WQ.png" /></figure><p>Now we just need to set up the payment methods in Google play and purchase products.</p><p>You can find the complete source of this project from below Github link.</p><p><a href="https://github.com/NandagopalR/GoolgePlay-Billing-Sample">NandagopalR/GoolgePlay-Billing-Sample</a></p><p>Thanks :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6eb6af176a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>