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

推荐订阅源

人人都是产品经理
人人都是产品经理
博客园_首页
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
小众软件
小众软件
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
月光博客
月光博客
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
IT之家
IT之家
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog

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
SafeSMS: On-Device Threat Detection with Gemma 4 E4B, no ...
Parul Malhot · 2026-05-23 · via DEV Community

This is a submission for the Gemma 4 Challenge: Build with Gemma 4

What I Built

SafeSMS is a privacy-first Android application designed to protect users from the rising threat of SMS-based scams, phishing, and spam.

Traditional SMS scanners and spam filters often send your private text messages to the cloud for analysis, creating severe privacy concerns. SafeSMS takes a completely different approach: it brings the intelligence directly to the device.

By running a powerful, on-device AI model, it performs real-time threat detection locally on your phone. It monitors incoming messages, categorizes them (SAFE, SUSPICIOUS, or SCAM), provides a confidence score, and explains why a message is dangerous.

The app features a sleek dark-mode UI built with Jetpack Compose, including:

  • Live scanning “terminal” view
  • Detailed history logs
  • Visual analytics for inbox threat patterns

✨ Example Detection

Incoming SMS:

Your bank account will be blocked. Click immediately: http://bit.ly/xyz

Enter fullscreen mode Exit fullscreen mode

SafeSMS Output:

  • Category: SCAM
  • Confidence: 92%
  • Reason:
    • Urgent language ("immediately")
    • Suspicious shortened URL
    • Impersonation of financial institution

Demo

[https://youtu.be/2NhvyiARX1c]


Code


How I Used Gemma 4

To enable real-time, completely private SMS analysis, SafeSMS uses Gemma 4 via LiteRT for on-device inference.

Model Selection: Gemma 4 E4B

I selected the E4B model because it perfectly fits mobile and edge environments:

  1. Absolute Privacy

    All SMS data stays on-device. No cloud calls, no data leakage.

  2. Zero Latency & Offline Capability

    Messages are analyzed instantly without any network dependency.

  3. Resource Efficiency

    The lightweight model runs efficiently inside a background Android service with minimal battery impact.

  4. Strong Reasoning in a Small Model

    Despite its compact size, the model effectively detects:

    • Phishing attempts
    • Social engineering patterns
    • Urgency-based scams

🧠 Prompting Strategy

The model is prompted using a structured classification + reasoning format, enabling it to return:

  • Label (SAFE / SUSPICIOUS / SCAM)
  • Confidence score
  • Explanation

This ensures both accuracy and transparency in predictions.


⚡ Performance

  • Inference Time: ~50–150 ms per SMS
  • Runs fully offline
  • Optimized for low battery usage
  • No network permissions required (privacy-first design)

🏗️ Architecture

SafeSMS follows a fully on-device architecture, ensuring privacy, speed, and reliability.

🔄 Flow Overview

  1. Incoming SMS

    • Captured via Android Broadcast Receiver
  2. Protection Service

    • Background service processes SMS in real time
  3. SafeSMS Model Controller

    • Handles preprocessing, inference, and routing
  4. On-Device AI Inference

    • Gemma 4 E4B via LiteRT
    • Classifies SMS into SAFE / SUSPICIOUS / SCAM
  5. Result Handling

    • Stored in local SQLite database
    • Sent instantly to UI
  6. User Interface (Jetpack Compose)

    • Live scan results
    • History and analytics dashboard

🧩 Architecture Components

  • SMS Layer: Broadcast Receiver
  • Processing Layer: Background Protection Service
  • AI Layer: LiteRT + Gemma 4
  • Data Layer: SQLite (local storage)
  • UI Layer: Jetpack Compose

🚀 Why This Architecture?

  • 🔒 Fully private (on-device processing only)
  • ⚡ Real-time detection with minimal latency
  • 📡 Works completely offline
  • 📊 Local analytics and history tracking
  • 🧠 Efficient AI optimized for mobile devices

🔮 Future Improvements

  • Multi-language scam detection
  • WhatsApp and email integration
  • Personalized scam pattern learning
  • Federated learning (privacy-preserving improvements)

🏁 Final Thoughts

SafeSMS demonstrates how powerful AI models like Gemma 4 can run entirely on-device, enabling real-world applications that are fast, private, and reliable.

It’s a step toward a future where user data never has to leave their device to stay safe.