/mobile-app-features

How to Add Dynamic QR Code Generation to Your Mobile App

Learn how to add dynamic QR code generation to your mobile app with this easy, step-by-step guide for seamless integration.

Book a free  consultation
4.9
Clutch rating 🌟
600+
Happy partners
17+
Countries served
190+
Team members
Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

How to Add Dynamic QR Code Generation to Your Mobile App

Adding Dynamic QR Code Generation to Your Mobile App

 

Why Dynamic QR Codes Matter

 

Static QR codes are like permanent tattoos—once created, they point to the same information forever. Dynamic QR codes, on the other hand, are like digital chameleons that can change their destination without changing their appearance. For business applications, this distinction is crucial.

 

  • With dynamic QR codes, you can update the destination URL without regenerating the code
  • You can track scans, locations, and user engagement
  • They enable personalized experiences based on user data

 

Architecture Overview: The Three-Layer Approach

 

The most sustainable approach for implementing dynamic QR codes involves three distinct layers:

 

  • Frontend Layer: The mobile app interface where users generate and view QR codes
  • Backend Service: Manages the QR code metadata, tracking, and redirection logic
  • QR Generation Engine: Creates the actual QR code images based on parameters

 

Think of this as a restaurant: your users see the dining area (frontend), the kitchen prepares the meals (backend service), and the chef's cooking techniques are the QR generation engine.

 

Implementation Steps

 

1. Setting Up the QR Generation Engine

 

You have two options here:

 

Option A: Use a third-party QR service

 

Services like QRCode Monkey API, QR Code Generator API, or GoQR.me offer ready-made solutions with tracking capabilities.

 

Option B: Create your own generator

 

For React Native apps:

 

// Install the required packages
// npm install react-native-qrcode-svg

import QRCode from 'react-native-qrcode-svg';

// Then in your component:
const MyQRCode = ({ value, size }) => (
  <QRCode 
    value={value}  // This will be your short URL that points to your backend
    size={size || 200}
    backgroundColor="white"
    color="black"
  />
);

 

For native iOS:

 

// In your ViewController or relevant class
import CoreImage.CIFilterBuiltins

func generateQRCode(from string: String) -> UIImage? {
    let context = CIContext()
    let filter = CIFilter.qrCodeGenerator()
    
    // Set the message content
    let data = string.data(using: .utf8)
    filter.setValue(data, forKey: "inputMessage")
    
    // Configure error correction - higher levels make QR codes more resilient but denser
    filter.setValue("M", forKey: "inputCorrectionLevel") // L, M, Q, H (low to high)
    
    // Get the output image
    if let outputImage = filter.outputImage {
        if let cgImage = context.createCGImage(outputImage, from: outputImage.extent) {
            return UIImage(cgImage: cgImage)
        }
    }
    return nil
}

 

For native Android:

 

// You'll need to add ZXing library to your build.gradle:
// implementation 'com.google.zxing:core:3.4.1'

import android.graphics.Bitmap
import com.google.zxing.BarcodeFormat
import com.google.zxing.MultiFormatWriter
import com.google.zxing.common.BitMatrix

fun generateQRCode(content: String, width: Int, height: Int): Bitmap? {
    try {
        val bitMatrix: BitMatrix = MultiFormatWriter().encode(
            content, BarcodeFormat.QR_CODE, width, height
        )
        val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
        
        for (x in 0 until width) {
            for (y in 0 until height) {
                bitmap.setPixel(x, y, if (bitMatrix[x, y]) 0xFF000000.toInt() else 0xFFFFFFFF.toInt())
            }
        }
        return bitmap
    } catch (e: Exception) {
        e.printStackTrace()
    }
    return null
}

 

2. Building the Backend Service

 

This is where the real magic of dynamic QR codes happens. Your backend needs to:

 

  • Generate short, unique identifiers for each QR code
  • Store metadata about each code (creation date, purpose, owner)
  • Track scanning events
  • Handle redirection based on parameters

 

Here's a simplified Node.js Express example of what this might look like:

 

const express = require('express');
const { v4: uuidv4 } = require('uuid');
const app = express();

// In-memory storage (use a database in production)
const qrCodes = {};
const scanEvents = [];

// Create a new dynamic QR code
app.post('/api/qr-codes', (req, res) => {
  const { destinationUrl, ownerId, metadata } = req.body;
  const id = uuidv4().substring(0, 8); // Short unique ID
  
  qrCodes[id] = {
    id,
    destinationUrl,
    ownerId,
    metadata,
    createdAt: new Date(),
    updatedAt: new Date()
  };
  
  // The URL to encode in the QR code
  const qrUrl = `https://yourdomain.com/q/${id}`;
  
  res.json({ 
    id, 
    qrUrl,
    // You could generate the QR code image here if not doing it client-side
  });
});

// Update a QR code's destination
app.put('/api/qr-codes/:id', (req, res) => {
  const { id } = req.params;
  const { destinationUrl, metadata } = req.body;
  
  if (!qrCodes[id]) {
    return res.status(404).json({ error: 'QR code not found' });
  }
  
  qrCodes[id].destinationUrl = destinationUrl;
  if (metadata) qrCodes[id].metadata = { ...qrCodes[id].metadata, ...metadata };
  qrCodes[id].updatedAt = new Date();
  
  res.json(qrCodes[id]);
});

// Handle QR code redirects
app.get('/q/:id', (req, res) => {
  const { id } = req.params;
  
  if (!qrCodes[id]) {
    return res.status(404).send('QR code not found');
  }
  
  // Record scan event
  scanEvents.push({
    qrId: id,
    timestamp: new Date(),
    userAgent: req.headers['user-agent'],
    ipAddress: req.ip,
    // Add other relevant tracking data
  });
  
  // Redirect to the destination URL
  res.redirect(qrCodes[id].destinationUrl);
});

// Get analytics for a QR code
app.get('/api/qr-codes/:id/analytics', (req, res) => {
  const { id } = req.params;
  
  if (!qrCodes[id]) {
    return res.status(404).json({ error: 'QR code not found' });
  }
  
  const qrScans = scanEvents.filter(event => event.qrId === id);
  
  res.json({
    qrCode: qrCodes[id],
    totalScans: qrScans.length,
    scans: qrScans
  });
});

app.listen(3000, () => {
  console.log('QR code service running on port 3000');
});

 

3. Integrating with Your Mobile App

 

The frontend integration typically involves:

 

  • A QR code generation screen with customization options
  • Storage of created QR codes for later reference
  • Analytics display for each code

 

React Native Example:

 

import React, { useState } from 'react';
import { View, TextInput, Button, StyleSheet, Alert } from 'react-native';
import QRCode from 'react-native-qrcode-svg';
import api from '../services/api'; // Your API client

const QRCodeGenerator = () => {
  const [destination, setDestination] = useState('');
  const [qrData, setQRData] = useState(null);
  const [isLoading, setIsLoading] = useState(false);
  
  const generateQRCode = async () => {
    if (!destination) {
      Alert.alert('Error', 'Please enter a destination URL');
      return;
    }
    
    setIsLoading(true);
    try {
      const response = await api.post('/api/qr-codes', {
        destinationUrl: destination,
        metadata: {
          purpose: 'marketing',
          campaign: 'summer_2023'
        }
      });
      
      setQRData(response.data);
    } catch (error) {
      Alert.alert('Error', 'Failed to generate QR code');
      console.error(error);
    } finally {
      setIsLoading(false);
    }
  };
  
  return (
    <View style={styles.container}>
      <TextInput
        style={styles.input}
        placeholder="Enter destination URL"
        value={destination}
        onChangeText={setDestination}
      />
      
      <Button
        title="Generate QR Code"
        onPress={generateQRCode}
        disabled={isLoading}
      />
      
      {qrData && (
        <View style={styles.qrContainer}>
          <QRCode
            value={qrData.qrUrl}
            size={200}
            backgroundColor="white"
            color="black"
          />
        </View>
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 20,
    alignItems: 'center',
  },
  input: {
    width: '100%',
    height: 50,
    borderWidth: 1,
    borderColor: '#ccc',
    borderRadius: 5,
    marginBottom: 20,
    paddingHorizontal: 10,
  },
  qrContainer: {
    marginTop: 30,
    padding: 20,
    backgroundColor: '#f9f9f9',
    borderRadius: 10,
    alignItems: 'center',
  }
});

export default QRCodeGenerator;

 

Advanced Features Worth Implementing

 

1. Customization Options

 

Allow users to customize QR codes with:

 

  • Brand colors and logos in the center of the QR code
  • Different shapes for the QR code elements (rounded corners vs. sharp)
  • Background patterns or images (ensuring adequate contrast for scanning)

 

2. Smart Redirection Logic

 

// On your backend redirect handler
app.get('/q/:id', (req, res) => {
  const { id } = req.params;
  const userAgent = req.headers['user-agent'];
  const qrCode = qrCodes[id];
  
  if (!qrCode) {
    return res.status(404).send('QR code not found');
  }
  
  // Record scan event
  recordScan(id, req);
  
  // Determine platform for smart redirection
  const isIOS = /iPhone|iPad|iPod/i.test(userAgent);
  const isAndroid = /Android/i.test(userAgent);
  
  // Redirect based on platform, time of day, location, or other parameters
  if (isIOS && qrCode.metadata.iosUrl) {
    return res.redirect(qrCode.metadata.iosUrl);
  } else if (isAndroid && qrCode.metadata.androidUrl) {
    return res.redirect(qrCode.metadata.androidUrl);
  } else {
    return res.redirect(qrCode.destinationUrl);
  }
});

 

3. Comprehensive Analytics

 

  • Scan frequency by time of day/week
  • Geographic distribution of scans
  • Device types and operating systems
  • Conversion tracking (if the scan led to a purchase or other goal)

 

Common Pitfalls and How to Avoid Them

 

1. QR Code Density

 

The more data you put in a QR code, the denser and harder to scan it becomes. Always use short URLs in your QR codes that redirect through your backend.

 

2. Error Correction Levels

 

QR codes support different error correction levels (L, M, Q, H) which determine how much damage a code can sustain while remaining scannable:

 

  • L (Low): 7% of codewords can be restored
  • M (Medium): 15% of codewords can be restored
  • Q (Quartile): 25% of codewords can be restored
  • H (High): 30% of codewords can be restored

 

Higher correction levels make your code more resilient but also denser. For branded QR codes with logos, use at least Q or H level.

 

3. Testing Across Devices

 

Always test your QR codes on multiple devices and in various lighting conditions. Some older devices may struggle with highly customized or dense QR codes.

 

Performance Considerations

 

1. On-demand vs. Pre-generated

 

For mobile apps, consider whether to generate QR codes on-demand or pre-generate and cache them:

 

  • On-demand: Generates fresh when needed, but may cause UI lag
  • Pre-generated: Better performance but consumes more storage

 

2. Backend Scalability

 

Your redirection backend is a critical path in the QR code experience. Ensure it's:

 

  • Highly available (consider serverless functions)
  • Geographically distributed for low latency
  • Cached appropriately to handle traffic spikes

 

Conclusion: The Business Impact

 

Dynamic QR codes aren't just a technical feature—they're a business strategy. They bridge physical and digital experiences while providing invaluable data about how users interact with your brand in the real world.

 

The implementation complexity is justified by the long-term flexibility: you can start with simple redirection and progressively enhance your QR system with analytics, personalization, and campaign tracking as your needs evolve.

 

Remember: The QR code itself is just the visible tip of the iceberg. The real value comes from the dynamic infrastructure you build underneath it, turning simple black-and-white squares into powerful, adaptive tools for customer engagement.

Ship Dynamic QR Code Generation 10x Faster with RapidDev

Connect with our team to unlock the full potential of code solutions with a no-commitment consultation!

Book a Free Consultation

Top 3 Mobile App Dynamic QR Code Generation Usecases

Explore the top 3 dynamic QR code use cases to boost your mobile app’s functionality and user engagement.

Time-Limited Promotional QR Codes

 

  • Generate QR codes that expire after a set period, perfect for flash sales, limited-time offers, or event-specific promotions. When scanned after expiration, they can redirect to alternative content (like your regular product page or a "promotion ended" message).

Dynamic User Authentication

 

  • Create temporary access credentials via QR codes that refresh every few minutes for secure facility access, event check-ins, or sensitive information sharing. This dramatically reduces the security risks associated with static QR codes that can be screenshotted and shared.

Personalized Customer Journey QR Codes

 

  • Generate unique QR codes tied to individual user profiles that adapt content based on customer history, preferences, and loyalty status. When scanned, these codes deliver personalized product recommendations, loyalty rewards, or tailored in-store navigation assistance—all updated in real-time without requiring new code generation.

 


Recognized by the best

Trusted by 600+ businesses globally

From startups to enterprises and everything in between, see for yourself our incredible impact.

RapidDev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with.

They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

Arkady
CPO, Praction
Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost.

He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Donald Muir
Co-Founder, Arc
RapidDev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space.

They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Mat Westergreen-Thorne
Co-CEO, Grantify
RapidDev is an excellent developer for custom-code solutions.

We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Emmanuel Brown
Co-Founder, Church Real Estate Marketplace
Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 

This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Samantha Fekete
Production Manager, Media Production Company
The pSEO strategy executed by RapidDev is clearly driving meaningful results.

Working with RapidDev has delivered measurable, year-over-year growth. Comparing the same period, clicks increased by 129%, impressions grew by 196%, and average position improved by 14.6%. Most importantly, qualified contact form submissions rose 350%, excluding spam.

Appreciation as well to Matt Graham for championing the collaboration!

Michael W. Hammond
Principal Owner, OCD Tech

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.Â