惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Last Week in AI
Last Week in AI
D
DataBreaches.Net
腾讯CDC
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
云风的 BLOG
云风的 BLOG
罗磊的独立博客
月光博客
月光博客
MyScale Blog
MyScale Blog
U
Unit 42
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
G
Google Developers Blog
博客园 - 【当耐特】
D
Docker
I
InfoQ
雷峰网
雷峰网

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Zero Internet? No Problem: How I Built Offline P2P Sharin...
Bratik Mukhe · 2026-04-29 · via DEV Community

Bratik Mukherjee

This is a great strategy for Dev.to and Hashnode. Articles that solve a specific technical problem—like offline data transfer—perform much better than general "I made an app" posts because they provide immediate value to other developers.

DEMO

Here is a ready-to-publish Markdown draft for your technical article.


Zero Internet? No Problem: How I Built Offline P2P Sharing Using QR Codes in Android

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 right now. Without an internet connection, how do you send it?

This was the challenge I faced while building bDoci, 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.

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

The Logic Flow

The goal is to move a structured Doc object from Device A's database to Device B's database using the camera as the data bridge.

  1. Serialize: Convert the Room Entity (Kotlin Data Class) to a JSON string.
  2. Encode: Convert that JSON to a Base64 string to keep the URI safe.
  3. Generate: Convert the Base64 string into a QR code.
  4. Broadcast: Embed the QR data into a custom URI scheme (bdoci://share/...).
  5. Receive: Use an Android Intent Filter to catch the link and inject the data.

🛠 The Code: From Object to Image

To handle the heavy lifting, I used GSON for serialization and ZXing for QR generation.

1. Serializing the Document

First, we turn our documentation object into a format that can be embedded in a URL.

fun generateShareUrl(doc: Doc): String {
    // 1. Convert Object to JSON
    val json = Gson().toJson(doc)

    // 2. Encode to Base64 to handle special characters in the URL
    val encodedData = Base64.encodeToString(json.toByteArray(), Base64.URL_SAFE or Base64.NO_WRAP)

    // 3. Return the custom Deep Link
    return "bdoci://share/$encodedData"
}

Enter fullscreen mode Exit fullscreen mode

2. Generating the QR Code

Once we have our URL, we need to draw it as a QR code that the recipient can scan.

fun generateQRCode(content: String): Bitmap {
    val writer = MultiFormatWriter()
    val matrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512)
    val encoder = BarcodeEncoder()
    return encoder.createBitmap(matrix)
}

Enter fullscreen mode Exit fullscreen mode


📡 The Intent: Catching the Data

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

I configured the AndroidManifest.xml with an <intent-filter> to catch the custom bdoci:// scheme:

<activity android:name=".Dashboard">
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="bdoci" android:host="share" />
    </intent-filter>
</activity>

Enter fullscreen mode Exit fullscreen mode

In the Dashboard.kt activity, I added a listener to handle the incoming data:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val data: Uri? = intent?.data
    if (data != null && data.scheme == "bdoci") {
        val encodedData = data.lastPathSegment
        val decodedJson = String(Base64.decode(encodedData, Base64.URL_SAFE))

        // Convert back to Object and save to local Room Database
        val sharedDoc = Gson().fromJson(decodedJson, Doc::class.java)
        viewModel.insert(sharedDoc)

        Toast.makeText(this, "Received: ${sharedDoc.title}", Toast.LENGTH_SHORT).show()
    }
}

Enter fullscreen mode Exit fullscreen mode


Why this works so well

By using Base64 encoding and Deep Links, 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.

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.

Check out the project

I implemented this entire system (along with a floating window PiP mode and Gruvbox aesthetics) in my open-source app, bDoci.

If you want to see the full implementation or contribute to the project:

💻 Source Code: GitHub - bimbok/bdoci-app
📱 Download the APK: Latest Release

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

Android #Kotlin #OpenSource #SoftwareArchitecture #MobileDev


Pro-Tips for Dev.to / Hashnode:

  1. The Cover Image: 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."
  2. Interactive Code: If you use Gists, you can embed them directly for better syntax highlighting.
  3. Engagement: 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!