<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bratik Mukherjee</title>
    <description>The latest articles on DEV Community by Bratik Mukherjee (@bimbok).</description>
    <link>https://dev.to/bimbok</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3904553%2F183351de-d351-4510-bf8d-72137aac88f5.jpg</url>
      <title>DEV Community: Bratik Mukherjee</title>
      <link>https://dev.to/bimbok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bimbok"/>
    <language>en</language>
    <item>
      <title>Zero Internet? No Problem: How I Built Offline P2P Sharing Using QR Codes in Android</title>
      <dc:creator>Bratik Mukherjee</dc:creator>
      <pubDate>Wed, 29 Apr 2026 15:14:32 +0000</pubDate>
      <link>https://dev.to/bimbok/zero-internet-no-problem-how-i-built-offline-p2p-sharing-using-qr-codes-in-android-4phg</link>
      <guid>https://dev.to/bimbok/zero-internet-no-problem-how-i-built-offline-p2p-sharing-using-qr-codes-in-android-4phg</guid>
      <description>&lt;p&gt;This is a great strategy for Dev.to and Hashnode. Articles that solve a specific technical problem—like &lt;strong&gt;offline data transfer&lt;/strong&gt;—perform much better than general "I made an app" posts because they provide immediate value to other developers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtube.com/shorts/GQ0UcGhralM?feature=share" rel="noopener noreferrer"&gt;DEMO&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is a ready-to-publish Markdown draft for your technical article.&lt;/p&gt;




&lt;h1&gt;
  
  
  Zero Internet? No Problem: How I Built Offline P2P Sharing Using QR Codes in Android
&lt;/h1&gt;

&lt;p&gt;Imagine you’re in a basement lab, a subway, or a remote area with zero bars of signal. You find a vital piece of documentation or a complex algorithm on your phone that your teammate needs &lt;em&gt;right now&lt;/em&gt;. Without an internet connection, how do you send it?&lt;/p&gt;

&lt;p&gt;This was the challenge I faced while building &lt;a href="https://github.com/your-repo-link" rel="noopener noreferrer"&gt;&lt;strong&gt;bDoci&lt;/strong&gt;&lt;/a&gt;, an open-source documentation hub for developers. I didn't want to rely on Bluetooth pairing or local Wi-Fi hotspots, which can be finicky. &lt;/p&gt;

&lt;p&gt;Instead, I built a &lt;strong&gt;Zero-Network P2P Sync&lt;/strong&gt; system using nothing but JSON serialization, QR codes, and Android Deep Links. Here is how I did it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Logic Flow
&lt;/h2&gt;

&lt;p&gt;The goal is to move a structured &lt;code&gt;Doc&lt;/code&gt; object from Device A's database to Device B's database using the camera as the data bridge.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Serialize:&lt;/strong&gt; Convert the Room Entity (Kotlin Data Class) to a JSON string.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encode:&lt;/strong&gt; Convert that JSON to a Base64 string to keep the URI safe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generate:&lt;/strong&gt; Convert the Base64 string into a QR code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Broadcast:&lt;/strong&gt; Embed the QR data into a custom URI scheme (&lt;code&gt;bdoci://share/...&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Receive:&lt;/strong&gt; Use an Android Intent Filter to catch the link and inject the data.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🛠 The Code: From Object to Image
&lt;/h2&gt;

&lt;p&gt;To handle the heavy lifting, I used &lt;strong&gt;GSON&lt;/strong&gt; for serialization and &lt;strong&gt;ZXing&lt;/strong&gt; for QR generation.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Serializing the Document
&lt;/h3&gt;

&lt;p&gt;First, we turn our documentation object into a format that can be embedded in a URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;generateShareUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Doc&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 1. Convert Object to JSON&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;json&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Gson&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;toJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;// 2. Encode to Base64 to handle special characters in the URL&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;encodedData&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encodeToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toByteArray&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nc"&gt;Base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;URL_SAFE&lt;/span&gt; &lt;span class="n"&gt;or&lt;/span&gt; &lt;span class="nc"&gt;Base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NO_WRAP&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;// 3. Return the custom Deep Link&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"bdoci://share/$encodedData"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Generating the QR Code
&lt;/h3&gt;

&lt;p&gt;Once we have our URL, we need to draw it as a QR code that the recipient can scan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;generateQRCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nc"&gt;Bitmap&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;writer&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MultiFormatWriter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;matrix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;writer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;BarcodeFormat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;QR_CODE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;encoder&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BarcodeEncoder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;encoder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createBitmap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  📡 The Intent: Catching the Data
&lt;/h2&gt;

&lt;p&gt;The "magic" happens on the receiving device. When the user scans the QR code with their native camera, Android needs to know that &lt;strong&gt;bDoci&lt;/strong&gt; is the app responsible for that specific link. &lt;/p&gt;

&lt;p&gt;I configured the &lt;code&gt;AndroidManifest.xml&lt;/code&gt; with an &lt;code&gt;&amp;lt;intent-filter&amp;gt;&lt;/code&gt; to catch the custom &lt;code&gt;bdoci://&lt;/code&gt; scheme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;activity&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;".Dashboard"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;intent-filter&lt;/span&gt; &lt;span class="na"&gt;android:autoVerify=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;action&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.action.VIEW"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.DEFAULT"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;category&lt;/span&gt; &lt;span class="na"&gt;android:name=&lt;/span&gt;&lt;span class="s"&gt;"android.intent.category.BROWSABLE"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

        &lt;span class="nt"&gt;&amp;lt;data&lt;/span&gt; &lt;span class="na"&gt;android:scheme=&lt;/span&gt;&lt;span class="s"&gt;"bdoci"&lt;/span&gt; &lt;span class="na"&gt;android:host=&lt;/span&gt;&lt;span class="s"&gt;"share"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/intent-filter&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/activity&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;Dashboard.kt&lt;/code&gt; activity, I added a listener to handle the incoming data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bundle&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Uri&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="o"&gt;?.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="p"&gt;!=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scheme&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"bdoci"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;encodedData&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lastPathSegment&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;decodedJson&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encodedData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Base64&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;URL_SAFE&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

        &lt;span class="c1"&gt;// Convert back to Object and save to local Room Database&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;sharedDoc&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Gson&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;fromJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;decodedJson&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Doc&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sharedDoc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="nc"&gt;Toast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;makeText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Received: ${sharedDoc.title}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Toast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LENGTH_SHORT&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why this works so well
&lt;/h2&gt;

&lt;p&gt;By using &lt;strong&gt;Base64 encoding&lt;/strong&gt; and &lt;strong&gt;Deep Links&lt;/strong&gt;, we eliminate the need for a server middleman. The data never touches the cloud—it moves at the speed of light from one screen to another lens. &lt;/p&gt;

&lt;p&gt;For developer tools, this type of reliability is crucial. Whether you're in a high-security server room with no Wi-Fi or a rural area with poor 4G, your knowledge base remains collaborative.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check out the project
&lt;/h2&gt;

&lt;p&gt;I implemented this entire system (along with a floating window PiP mode and Gruvbox aesthetics) in my open-source app, &lt;strong&gt;bDoci&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you want to see the full implementation or contribute to the project:&lt;/p&gt;

&lt;p&gt;💻 &lt;strong&gt;Source Code:&lt;/strong&gt; &lt;a href="https://github.com/Bimbok/bDoci-app.git[](url)" rel="noopener noreferrer"&gt;GitHub - bimbok/bdoci-app&lt;/a&gt;&lt;br&gt;
📱 &lt;strong&gt;Download the APK:&lt;/strong&gt; &lt;a href="https://github.com/Bimbok/bDoci-app/releases/tag/v3.7.5" rel="noopener noreferrer"&gt;Latest Release&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your thoughts on this offline-sync approach! What other creative ways have you used QR codes in your apps?&lt;/p&gt;

&lt;h1&gt;
  
  
  Android #Kotlin #OpenSource #SoftwareArchitecture #MobileDev
&lt;/h1&gt;




&lt;h3&gt;
  
  
  Pro-Tips for Dev.to / Hashnode:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Cover Image:&lt;/strong&gt; Use a tool like Canva to make a simple thumbnail. Put a QR code on one side and the Android logo on the other with the text "Offline P2P Sharing."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interactive Code:&lt;/strong&gt; If you use Gists, you can embed them directly for better syntax highlighting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Engagement:&lt;/strong&gt; After you post, check the comments! People might ask about the character limit of QR codes (which is about 2,953 bytes for alphanumeric data)—be ready to explain that you keep your document objects lightweight!&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>android</category>
      <category>networking</category>
      <category>showdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
