Skip to content

CodedByManish/Offline-ChatApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🌌 Offline ChatApp: P2P Local Mesh

A high-performance, serverless messaging application for Android that enables real-time 1-on-1 private chatting within a 50m-100m range. This project focuses on a "WhatsApp-style" user experience, where connections are made once and remembered for life, allowing for automatic background syncing whenever devices are in proximity.


✨ Key Features

  • 🆔 ID-Based Identity: Every user is assigned a unique device-specific ID and profile.
  • 🤝 Secure Handshake: A one-time manual "Request & Accept" protocol to establish a trusted friendship.
  • ⚡ Auto-Reconnect: Once "paired," devices automatically establish a chat link in the background whenever they are in range.
  • 🔒 Private 1-on-1 Rooms: Sophisticated message routing ensures data is only visible to the intended recipient.
  • 🌑 Premium UI/UX: A minimalist, glassmorphic dark-theme design with soft shadows and rounded modern aesthetics.
  • 📡 No Internet Required: Operates entirely over Bluetooth and WiFi Direct using the Google Nearby Connections API.

🛠 Tech Stack

  • Platform: Android (Java)
  • Communication: Google Nearby Connections API (P2P_CLUSTER)
  • Database: SQLite / Room (For persistent Friendships & History)
  • Architecture: MVVM-inspired with a Foreground Service for background resilience.
  • Styling: XML with custom Drawables and Material Design 3.

📂 Project Structure & File Map

OfflineChatApp/
├── app/
│   ├── src/
│   │   ├── main/
│   │   │   ├── java/com/example/offlinechatapp/
│   │   │   │   ├── activities/
│   │   │   │   │   ├── MainActivity.java      # Primary entry point; displays the Friend List.
│   │   │   │   │   ├── DiscoveryActivity.java # Handles searching for and adding new nearby users.
│   │   │   │   │   └── ChatActivity.java      # Real-time messaging interface for 1-on-1 rooms.
│   │   │   │   ├── adapter/
│   │   │   │   │   ├── FriendAdapter.java     # Binds the local database friends to the UI list.
│   │   │   │   │   └── MessageAdapter.java    # Handles multi-view bubbles (Sent vs Received).
│   │   │   │   ├── database/
│   │   │   │   │   ├── AppDatabase.java       # Room database initialization.
│   │   │   │   │   ├── FriendDao.java         # Data Access Object for CRUD operations.
│   │   │   │   │   └── FriendEntity.java      # Database schema for storing "Accepted" friends.
│   │   │   │   ├── models/
│   │   │   │   │   ├── User.java              # Object representing a nearby peer.
│   │   │   │   │   └── Message.java           # Object representing an individual chat message.
│   │   │   │   ├── services/
│   │   │   │   │   └── P2PService.java        # The engine; runs in the background to maintain links.
│   │   │   │   └── utils/
│   │   │   │       └── NearbyManager.java     # Configuration for P2P_CLUSTER and Service IDs.
│   │   │   ├── res/
│   │   │   │   ├── layout/                    # Glassmorphic UI layouts for all screens.
│   │   │   │   └── drawable/                  # Custom bubble shapes and shadow definitions.
│   │   │   └── AndroidManifest.xml            # Bluetooth, WiFi, and Background Service permissions.

⚙️ How It Works (The Logic)

🔍 The Discovery Phase

When you open DiscoveryActivity, the app uses NearbyManager settings to start scanning nearby devices.
When a device is found, it appears in your list. You send a connection request, and the other user must accept it.

🤝 The Friendship Bond

Once a connection is accepted, the peer's unique ID is saved into the FriendEntity table in the local AppDatabase.
This marks them as Trusted devices.

🔄 Background Syncing

P2PService runs as a Foreground Service. It continuously scans for devices stored in the FriendEntity table.
When a friend is nearby, it connects silently without asking for permission again.

💬 Message Routing

In ChatActivity, messages are sent as byte payloads.
Each payload is tagged with the receiver's endpointId, ensuring that even if multiple users are nearby, the message is delivered only to the correct chat window.


🚀 Getting Started

📥 Clone the Repo

git clone https://github.com/yourusername/Offline-ChatApp.git

📦 Dependencies

Add play-services-nearby and Room dependencies in your build.gradle.

🔐 Permissions

Grant Location, Bluetooth, and Nearby Device permissions on both physical devices.

📲 Deploy

Install the APK on two Android devices. Tap the "+" button on one device to discover the other.

About

Offline-ChatApp: An open-source, P2P mesh messaging app for Android. Secure, serverless, and private communication using Bluetooth & WiFi Direct.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages