Connect to bluetooth printer in Mobile app by React Native

To connect to a Bluetooth printer using React Native, you can use the react-native-bluetooth-serial library, which is one of the commonly used libraries for interacting with Bluetooth devices, including printers. Below is a step-by-step guide to setting up your React Native app for connecting to a Bluetooth printer.

Steps to Connect Bluetooth Printer in React Native:

Install Dependencies: First, you’ll need to install the necessary libraries.

npm install --save react-native-bluetooth-serial

If you’re using React Native 0.59 or earlier, you’ll need to link the package:

react-native link react-native-bluetooth-serial

Below is the React Native code to connect to a Bluetooth printer.

import React, { useState, useEffect } from 'react';
import { View, Button, Text, PermissionsAndroid, Platform } from 'react-native';
import BluetoothSerial from 'react-native-bluetooth-serial';

const BluetoothPrinter = () => {
  const [isConnected, setIsConnected] = useState(false);
  const [devices, setDevices] = useState([]);
  const [selectedDevice, setSelectedDevice] = useState(null);

  useEffect(() => {
    // Request Bluetooth permission (Android only)
    if (Platform.OS === 'android') {
      PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.BLUETOOTH)
        .then(() => {
          // Start Bluetooth scanning on permission granted
          BluetoothSerial.list()
            .then(devices => setDevices(devices))
            .catch(err => console.error(err));
        })
        .catch(err => console.error('Permission denied', err));
    } else {
      BluetoothSerial.list()
        .then(devices => setDevices(devices))
        .catch(err => console.error(err));
    }

    // Cleanup when component unmounts
    return () => {
      BluetoothSerial.stopScanning();
    };
  }, []);

  const connectToDevice = (device) => {
    BluetoothSerial.connect(device.id)
      .then(() => {
        setSelectedDevice(device);
        setIsConnected(true);
      })
      .catch(err => console.error('Connection failed', err));
  };

  const disconnect = () => {
    BluetoothSerial.disconnect()
      .then(() => {
        setIsConnected(false);
        setSelectedDevice(null);
      })
      .catch(err => console.error('Disconnection failed', err));
  };

  const printReceipt = () => {
    if (isConnected && selectedDevice) {
      // Here, you can send data to the printer
      const data = 'Hello Printer!';
      BluetoothSerial.write(data)
        .then(() => console.log('Data sent to printer'))
        .catch(err => console.error('Failed to print', err));
    } else {
      console.log('No device connected');
    }
  };

  return (
    
      Bluetooth Printer Connection

      
        Select Device
        {devices.length > 0 ? (
          devices.map((device) => (
             connectToDevice(device)}
            />
          ))
        ) : (
          No devices found
        )}
      

      
        {isConnected ? (
          
            Connected to {selectedDevice?.name}
            
            
          
        ) : (
          Not connected to any device
        )}
      
    
  );
};

The Top 5 popular content management system using .NET framework in 2020.

A Content Management System (CMS) is a software platform that allows users to create, manage, and modify digital content on a website without needing advanced technical skills like coding. It is extremely important for blogger, business owners or companies—it’s a foundational tool for managing their online presence efficiently and professionally.

Why do people use a CMS

Ease of Use – Allows non-developers (like marketers, editors, business owners) to manage content without writing code.

Faster Deployment – Build and launch websites quickly using templates and drag-and-drop editors.

Collaboration – Multiple users can manage, edit, and publish content simultaneously.

Scalability – CMS platforms can support everything from small blogs to enterprise-level websites.

Content Organization – Helps manage large volumes of structured (like articles) and unstructured (like images, videos) content.

SEO Optimization – Most CMS platforms have built-in SEO tools (meta tags, friendly URLs, sitemaps) or plugins to improve search engine visibility.

Let’s find out what are the most popular content management system using .NET framework:


Umbraco
umbraco.com
Umbraco is a highly flexible, open-source CMS with a strong focus on developer experience. Built with .NET, it supports MVC, Razor, and a customizable back-office UI. It’s widely used for both small and enterprise-level websites.

Highlights: Open-source, flexible, strong developer tools
Type: Free (with paid plans)
Cost: Free (Cloud plans from ~$40/month)
Support: ★★★★☆ (Email, forum, optional phone for paid)
Community: Large, active
Used by: Heinz, Mercedes-Benz, Warner Bros


Sitefinity
sitefinity.com
Sitefinity by Progress is a robust CMS designed for enterprise users. It offers marketing automation, headless API support, and high scalability. Great for content-heavy and multilingual sites.

Highlights: Drag-and-drop UI, personalization, multilingual
Type: Commercial
Cost: Starts around $3,000/year
Support: ★★★★★ (Phone, email, tickets)
Community: Moderate
Used by: NASA, Microsoft, Coca-Cola


Kentico
kentico.com
Kentico is an integrated CMS, e-commerce, and marketing platform. Built on ASP.NET MVC, it’s aimed at enterprise solutions with a full-featured backend, great customization, and scalability.

Highlights: All-in-one CMS + digital marketing, e-commerce
Type: Commercial
Cost: Starts around $7,999/year
Support: ★★★★★ (Phone, tickets, partners)
Community: Strong developer community
Used by: Starbucks, Mazda, Allergan


DotNetNuke
dnnsoftware.com
DNN is one of the oldest and most stable .NET CMS platforms. The free version (DNN Platform) is open-source and extendable; the Evoq version adds premium features and support.

Highlights: Open-source, modular, mature
Type: Free (Platform) / Commercial
Cost: Commercial starts at ~$2,000/year
Support: ★★★★☆ (Phone, email for Commercial)
Community: Large, long-standing
Used by: Bank of America, BP, Samsung


Orchard Core (formerly Orchard CMS)
orchardcore.net
Orchard Core is the newer, high-performance rework of the original Orchard CMS, now based on ASP.NET Core. Ideal for developers wanting a lightweight, headless-capable CMS. It’s modular, secure, and open-source.

Highlights: Modular, modern ASP.NET Core-based, headless-ready
Type: Free
Cost: Free
Support: ★★★☆☆ (GitHub issues, community)
Community: Growing, mainly developers
Used by: Microsoft, Lombiq, small businesses

Display datetime based on user’s timezone in Asp.Net MVC

When creating an internet application/website, your users located anywhere in the world, therefore it’s important to let user to choose their own timezone and display the datetime information according to their location.

In this article, I am going to show you how to display all available Timezone information using Asp.Net MVC, and convert the original datetime to selected Timezone datetime.

img
Continue reading “Display datetime based on user’s timezone in Asp.Net MVC”

New Hosting, New Name

Finally, I had my blog moved to the new hosting. Besides that I gave the new name to my blog. It’s “Tien’s Blog” instead of “Platformular’s blog” which “Platformular “was the name of my Dev house. 

There are a few projects I am working on right now as well as blog articles. Hopfully they will be published soon.

Change to new blog hosting

It is troublesome when you start fighting spam for website, application or even this Blog!

There were a couple hundreds of thousands spam comments I deleted last week. Originally I was going to filter every comment and make sure that the useful comments can be posted. However, there were just too many spam comments to read through so I have to manually write a “delete *” sql commend against the MySQL.. (free up more than 4GB in disk space..LOL)

I am thinking to move my blog to wordpress.com where I can just concentrate more on writing instead of maintaining. If you have any ideas/suggestion about good blog host. email me at tien@platformular.com. I am looking to migrate my blog in 2 weeks

As the same time, I have a number of request about my blog articles and hopefully they are coming out at the same time when my new blog’s ready 🙂

Country Drop Down Html Helper for Asp.net MVC

Almost every website or web application need to display countries in the drop down list. If that’s true to your project, the following country drop down html helper for Asp.net MVC may save some time for you.

First, we need all the countries information so that we can put into the select list. Thanks to Mads, we can use the XML countries list. or you can download the countries XML List.

Second, A html helper is created for populating the country data into actual HTML format. Simply put the xml file in the App_Data or any folder that works the best for your application.

Continue reading “Country Drop Down Html Helper for Asp.net MVC”

Hello world!

Welcome to WordPress.com. After you read this, you should delete and write your own post, with a new title above. Or hit Add New on the left (of the admin dashboard) to start a fresh post.

Here are some suggestions for your first post.

  1. You can find new ideas for what to blog about by reading the Daily Post.
  2. Add PressThis to your browser. It creates a new blog post for you about any interesting  page you read on the web.
  3. Make some changes to this page, and then hit preview on the right. You can alway preview any post or edit you before you share it to the world.