跳過到頁腳內容
使用 IRONQR

如何掃描 QR Code Android (初學者教學)

如今二維碼隨處可見,它們可以作為訪問網站、獲取折扣或重要資訊的快捷連結。 然而,掃描這些設備的方法在不同的安卓設備上並不總是相同的。 根據你的手機型號,你可能可以使用內建的相機應用,或者你可能需要單獨的二維碼掃描器。 為了消除任何疑惑,我們整理了一份詳細的指南,幫助您在任何安卓智慧型手機或平板電腦上輕鬆掃描二維碼。 我們也將探索使用IronQR 函式庫以程式方式掃描二維碼的方法。

Android 內建掃描二維碼的方法

Android 裝置通常都具備原生支援二維碼掃描的功能。 這些內建方法既方便又安全,因為它們不需要安裝第三方應用程式。 讓我們來了解一下安卓設備用戶可用的主要內建選項。

1. Google Lens 應用

Google Lens 是一款功能強大的視覺化分析工具,包含二維碼掃描功能。 該應用程式通常預先安裝在安卓裝置上,可透過多種入口點存取。

造訪 Google 鏡頭

用戶可以透過多種方式在 Android 手機上存取 Google Lens,具體取決於他們的裝置和個人偏好。 最常用的方法是透過 Google 應用程式。以下是造訪 Google Lens 的步驟:

  1. 開啟谷歌應用程式。
  2. 在搜尋列附近找到 Google Lens 圖示。

如何在安卓裝置上掃描二維碼(新手教學):圖 1

  1. 點選圖示啟動 Google Lens。

對於那些喜歡使用現有圖像的用戶來說,Google Photos 提供了另一個入口。 具體流程如下:

  1. 開啟谷歌相簿。

  2. 選擇一張包含二維碼的圖片。

如何在安卓裝置上掃描二維碼(新手教學):圖 2

  1. 點擊螢幕底部的 Google Lens 圖示。 之後,您可以使用 Google Lens 功能進行二維碼掃描。

部分安卓設備,特別是運行較新版本作業系統的設備,將谷歌鏡頭直接整合到原生相機應用程式中。 這些裝置的使用者可以透過以下方式存取 Google Lens:

  1. 啟動相機應用。
  2. 尋找"模式"或"更多"選項。
  3. 如果可用,請選擇 Google Lens。

使用谷歌鏡頭進行二維碼掃描

啟動 Google Lens 後,掃描二維碼的過程非常簡單。 使用方法如下:

  1. 將設備的攝影機對準二維碼。
  2. 等待 Google Lens 自動開始掃描。
  3. 當辨識到二維碼時,會彈出一個視窗顯示編碼訊息。
  4. 點選彈出窗口,即可存取連結內容或執行相關操作。

2. 快速設定磁貼

部分安卓設備提供快速設定磁貼,方便使用者快速掃描二維碼,以便快速存取此功能。 設定和使用此功能:

  1. 從螢幕頂部向下滑動,即可開啟快速設定面板。

如何在安卓裝置上掃描二維碼(新手教學):圖 3

  1. 再次向下滑動即可展開整個面板。

如何在安卓裝置上掃描二維碼(新手教學):圖 4

  1. 找到編輯功能,通常用鉛筆圖示或三個點圖示表示。

如何在安卓裝置上掃描二維碼(新手教學):圖 5

  1. 在編輯模式下,搜尋標示為"QR 碼"或"QR 掃描器"的圖塊。

如何在安卓裝置上掃描二維碼(新手教學):圖 6

  1. 將此圖塊拖曳到活動的快速設定區域。
  2. 儲存變更以確認新佈局。

使用快速設定二維碼掃描器:

  1. 開啟快速設定面板。
  2. 點選二維碼掃描器方塊。
  3. 該裝置將啟動二維碼掃描介面,該介面可能會使用相機應用程式或 Google Lens。
  4. 將相機對準二維碼以啟動掃描。

這些內建方法為 Android 用戶提供了高效掃描二維碼的方式,無需安裝額外的軟體。 使用者可以快速存取二維碼中編碼的訊息,同時保持設備的安全性與完整性。 除此之外,你還可以透過 Google Play 商店在安卓手機上下載第三方二維碼掃描應用程式。

隆重推出 IronQR .NET 函式庫

雖然我們討論過的內建方法為最終用戶提供了出色的二維碼掃描功能,但開發人員通常需要更強大的工具來在其應用程式中建立和操作二維碼。 這時IronQR .NET函式庫就派上用場了。 它為安卓應用開發中的二維碼功能提供了一個強大的解決方案。

IronQR概述

如何在安卓裝置上掃描二維碼(新手教學):圖 7

IronQR是一個功能全面的 .NET 函式庫,旨在產生、讀取和操作二維碼。 雖然主要針對 .NET 開發人員,但可以透過 Xamarin 或 .NET MAUI 等框架在 Android 開發中使用。 它是具有二維碼功能的跨平台應用程式的完美選擇。

主要功能和優點

IronQR 提供了許多與二維碼功能相關的特性:

1.二維碼產生:開發人員可以透過程式設計方式建立二維碼,控制各種參數,如大小、糾錯等級和內容。 2.進階掃描功能:此函式庫提供強大的演算法來讀取二維碼,即使在具有挑戰性的條件下或從影像中讀取二維碼。 3.自訂選項:IronQR 允許建立自訂二維碼,包括新增徽標或自訂顏色,同時保持可掃描性。 4.支援多種資料類型:此程式庫可以將不同類型的資料(包括 URL、聯絡資訊和自訂文字)編碼為二維碼。 5.錯誤處理與修正:IronQR 實作了先進的錯誤修正技術,確保產生的二維碼可靠且易於掃描。

與 Android 開發集成

對於在 .NET 環境下工作的 Android 開發人員來說,可以將 IronQR 整合到專案中,以提供伺服器端二維碼產生或增強 Android 應用程式的功能。 這種整合可以實現更複雜的二維碼操作,而這些操作使用標準的 Android 函式庫可能無法實現。

開發者可以創建具有複雜二維碼功能的 Android 應用程序,例如批量生成二維碼、高級解碼功能或符合品牌要求的自訂二維碼設計。 IronQR .NET 函式庫是一個強大的工具,開發者可以透過它擴展 Android 應用程式的二維碼功能,使其超越標準的內建功能。

程式碼範例

這裡示範的是一個使用 IronQR 的 .NET MAUI 二維碼掃描器應用程式。 在專案中安裝 IronQR 庫後,更新MauiPage.xaml程式碼:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="QR_Code_Business_Card.MainPage"
             Title="QR Code Reader">
    <Grid Padding="20" RowDefinitions="Auto,*" ColumnDefinitions="*,Auto,*">
        <!-- Left side -->
        <VerticalStackLayout Grid.Row="1" Grid.Column="0" Spacing="20">
            <Button x:Name="ScanQRButton" 
                    Text="Scan QR Code"
                    Clicked="OnScanQRButtonClicked"
                    HorizontalOptions="Fill"
                    BackgroundColor="#6200EE"
                    TextColor="White"
                    FontAttributes="Bold"
                    CornerRadius="10" />
            <Frame BorderColor="#E0E0E0" Padding="0" CornerRadius="10" HasShadow="True">
                <Grid>
                    <Image x:Name="SelectedImage"
                           HeightRequest="300"
                           WidthRequest="300"
                           Aspect="AspectFit" />
                    <ActivityIndicator x:Name="LoadingIndicator"
                                       IsRunning="False"
                                       IsVisible="False"
                                       Color="#6200EE"
                                       VerticalOptions="Center"
                                       HorizontalOptions="Center" />
                </Grid>
            </Frame>
        </VerticalStackLayout>
        <!-- Divider -->
        <BoxView Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" 
                 WidthRequest="1" 
                 Color="#E0E0E0" 
                 Margin="10,0" />
        <!-- Right side -->
        <VerticalStackLayout Grid.Row="1" Grid.Column="2" Spacing="20">
            <Frame BorderColor="#E0E0E0" Padding="10" CornerRadius="10" HasShadow="True">
                <Editor x:Name="ResultEditor"
                        HeightRequest="200"
                        IsReadOnly="True"
                        Placeholder="QR code content will appear here"
                        FontSize="16" />
            </Frame>
            <Button x:Name="CopyTextButton" 
                    Text="Copy Text"
                    Clicked="OnCopyTextButtonClicked"
                    HorizontalOptions="Fill"
                    BackgroundColor="#6200EE"
                    TextColor="White"
                    FontAttributes="Bold"
                    CornerRadius="10" />
        </VerticalStackLayout>
    </Grid>
</ContentPage>
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="QR_Code_Business_Card.MainPage"
             Title="QR Code Reader">
    <Grid Padding="20" RowDefinitions="Auto,*" ColumnDefinitions="*,Auto,*">
        <!-- Left side -->
        <VerticalStackLayout Grid.Row="1" Grid.Column="0" Spacing="20">
            <Button x:Name="ScanQRButton" 
                    Text="Scan QR Code"
                    Clicked="OnScanQRButtonClicked"
                    HorizontalOptions="Fill"
                    BackgroundColor="#6200EE"
                    TextColor="White"
                    FontAttributes="Bold"
                    CornerRadius="10" />
            <Frame BorderColor="#E0E0E0" Padding="0" CornerRadius="10" HasShadow="True">
                <Grid>
                    <Image x:Name="SelectedImage"
                           HeightRequest="300"
                           WidthRequest="300"
                           Aspect="AspectFit" />
                    <ActivityIndicator x:Name="LoadingIndicator"
                                       IsRunning="False"
                                       IsVisible="False"
                                       Color="#6200EE"
                                       VerticalOptions="Center"
                                       HorizontalOptions="Center" />
                </Grid>
            </Frame>
        </VerticalStackLayout>
        <!-- Divider -->
        <BoxView Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" 
                 WidthRequest="1" 
                 Color="#E0E0E0" 
                 Margin="10,0" />
        <!-- Right side -->
        <VerticalStackLayout Grid.Row="1" Grid.Column="2" Spacing="20">
            <Frame BorderColor="#E0E0E0" Padding="10" CornerRadius="10" HasShadow="True">
                <Editor x:Name="ResultEditor"
                        HeightRequest="200"
                        IsReadOnly="True"
                        Placeholder="QR code content will appear here"
                        FontSize="16" />
            </Frame>
            <Button x:Name="CopyTextButton" 
                    Text="Copy Text"
                    Clicked="OnCopyTextButtonClicked"
                    HorizontalOptions="Fill"
                    BackgroundColor="#6200EE"
                    TextColor="White"
                    FontAttributes="Bold"
                    CornerRadius="10" />
        </VerticalStackLayout>
    </Grid>
</ContentPage>
XML

之後,更新MauiPage.xaml.cs程式碼:

using IronQr;
using IronSoftware.Drawing;
namespace QR_Code_Business_Card
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            License.LicenseKey = "License-Key";
        }

        private async void OnScanQRButtonClicked(object sender, EventArgs e)
        {
            try
            {
                var result = await FilePicker.PickAsync(new PickOptions
                {
                    FileTypes = FilePickerFileType.Images,
                    PickerTitle = "Pick an image with a QR code"
                });

                if (result != null)
                {
                    string filePath = result.FullPath;
                    SelectedImage.Source = ImageSource.FromFile(filePath);

                    // Show loading indicator
                    LoadingIndicator.IsVisible = true;
                    LoadingIndicator.IsRunning = true;
                    ResultEditor.Text = "Processing QR code...";

                    // Process QR code in the background
                    await Task.Run(() =>
                    {
                        var inputBmp = AnyBitmap.FromFile(filePath);
                        QrImageInput imageInput = new QrImageInput(inputBmp);
                        QrReader reader = new QrReader();
                        IEnumerable<QrResult> results = reader.Read(imageInput);

                        MainThread.BeginInvokeOnMainThread(() =>
                        {
                            if (results.Any())
                            {
                                string scannedData = results.First().Value.ToString();
                                ResultEditor.Text = scannedData;
                            }
                            else
                            {
                                ResultEditor.Text = "No QR code found in the image.";
                            }

                            // Hide loading indicator
                            LoadingIndicator.IsVisible = false;
                            LoadingIndicator.IsRunning = false;
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                ResultEditor.Text = $"An error occurred: {ex.Message}";
                LoadingIndicator.IsVisible = false;
                LoadingIndicator.IsRunning = false;
            }
        }

        private async void OnCopyTextButtonClicked(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(ResultEditor.Text))
            {
                await Clipboard.SetTextAsync(ResultEditor.Text);
                await DisplayAlert("Success", "Text copied to clipboard", "OK");
            }
            else
            {
                await DisplayAlert("Error", "No text to copy", "OK");
            }
        }
    }
}
using IronQr;
using IronSoftware.Drawing;
namespace QR_Code_Business_Card
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            License.LicenseKey = "License-Key";
        }

        private async void OnScanQRButtonClicked(object sender, EventArgs e)
        {
            try
            {
                var result = await FilePicker.PickAsync(new PickOptions
                {
                    FileTypes = FilePickerFileType.Images,
                    PickerTitle = "Pick an image with a QR code"
                });

                if (result != null)
                {
                    string filePath = result.FullPath;
                    SelectedImage.Source = ImageSource.FromFile(filePath);

                    // Show loading indicator
                    LoadingIndicator.IsVisible = true;
                    LoadingIndicator.IsRunning = true;
                    ResultEditor.Text = "Processing QR code...";

                    // Process QR code in the background
                    await Task.Run(() =>
                    {
                        var inputBmp = AnyBitmap.FromFile(filePath);
                        QrImageInput imageInput = new QrImageInput(inputBmp);
                        QrReader reader = new QrReader();
                        IEnumerable<QrResult> results = reader.Read(imageInput);

                        MainThread.BeginInvokeOnMainThread(() =>
                        {
                            if (results.Any())
                            {
                                string scannedData = results.First().Value.ToString();
                                ResultEditor.Text = scannedData;
                            }
                            else
                            {
                                ResultEditor.Text = "No QR code found in the image.";
                            }

                            // Hide loading indicator
                            LoadingIndicator.IsVisible = false;
                            LoadingIndicator.IsRunning = false;
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                ResultEditor.Text = $"An error occurred: {ex.Message}";
                LoadingIndicator.IsVisible = false;
                LoadingIndicator.IsRunning = false;
            }
        }

        private async void OnCopyTextButtonClicked(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(ResultEditor.Text))
            {
                await Clipboard.SetTextAsync(ResultEditor.Text);
                await DisplayAlert("Success", "Text copied to clipboard", "OK");
            }
            else
            {
                await DisplayAlert("Error", "No text to copy", "OK");
            }
        }
    }
}
Imports IronQr
Imports IronSoftware.Drawing
Namespace QR_Code_Business_Card
	Partial Public Class MainPage
		Inherits ContentPage

		Public Sub New()
			InitializeComponent()
			License.LicenseKey = "License-Key"
		End Sub

		Private Async Sub OnScanQRButtonClicked(ByVal sender As Object, ByVal e As EventArgs)
			Try
				Dim result = Await FilePicker.PickAsync(New PickOptions With {
					.FileTypes = FilePickerFileType.Images,
					.PickerTitle = "Pick an image with a QR code"
				})

				If result IsNot Nothing Then
					Dim filePath As String = result.FullPath
					SelectedImage.Source = ImageSource.FromFile(filePath)

					' Show loading indicator
					LoadingIndicator.IsVisible = True
					LoadingIndicator.IsRunning = True
					ResultEditor.Text = "Processing QR code..."

					' Process QR code in the background
					Await Task.Run(Sub()
						Dim inputBmp = AnyBitmap.FromFile(filePath)
						Dim imageInput As New QrImageInput(inputBmp)
						Dim reader As New QrReader()
						Dim results As IEnumerable(Of QrResult) = reader.Read(imageInput)

						MainThread.BeginInvokeOnMainThread(Sub()
							If results.Any() Then
								Dim scannedData As String = results.First().Value.ToString()
								ResultEditor.Text = scannedData
							Else
								ResultEditor.Text = "No QR code found in the image."
							End If

							' Hide loading indicator
							LoadingIndicator.IsVisible = False
							LoadingIndicator.IsRunning = False
						End Sub)
					End Sub)
				End If
			Catch ex As Exception
				ResultEditor.Text = $"An error occurred: {ex.Message}"
				LoadingIndicator.IsVisible = False
				LoadingIndicator.IsRunning = False
			End Try
		End Sub

		Private Async Sub OnCopyTextButtonClicked(ByVal sender As Object, ByVal e As EventArgs)
			If Not String.IsNullOrWhiteSpace(ResultEditor.Text) Then
				Await Clipboard.SetTextAsync(ResultEditor.Text)
				Await DisplayAlert("Success", "Text copied to clipboard", "OK")
			Else
				Await DisplayAlert("Error", "No text to copy", "OK")
			End If
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

運行應用程式後,您將看到以下使用者介面。 選擇二維碼後,它會掃描二維碼並在文字方塊中顯示結果文本,您可以使用複製按鈕複製該文本。

如何在安卓裝置上掃描二維碼(新手教學):圖 8

結論

如何在安卓裝置上掃描二維碼(新手教學):圖 9

借助 Google Lens 和快速設定磁貼等內建功能,在 Android 裝置上掃描二維碼變得非常簡單。 這些原生方法使用戶能夠快速且安全地存取二維碼訊息,而無需額外的應用程式。

對於希望將高階二維碼功能整合到其應用程式中的開發人員來說,IronQR .NET 程式庫提供了一個強大的解決方案。 它支援自訂二維碼生成、高級掃描功能和豐富的自訂選項。 IronQR 為開發者提供免費試用版,方便他們探索其各項功能,許可證起價為$799 ,對於在 Android 應用程式中集成專業級二維碼而言,這是一項值得的投資。

常見問題解答

如何使用 Android 裝置上的內建相機掃描 QR 碼?

如果內建的相機應用程式與 Google Lens 整合,您通常可以使用相機應用程式掃描 QR 代碼。打開相機,對準 QR 碼,如果支援的話,相機會顯示與 QR 碼相關的連結或動作。

什麼是 Google Lens,它如何用來掃瞄 Android 上的 QR 碼?

Google Lens 是一種視覺搜尋工具,包含 QR 碼掃描功能。您可以透過 Android 裝置上的 Google 應用程式或 Google Photos 來存取。若要掃描 QR 碼,請開啟 Google Lens,對準 QR 碼,它就會提供與 QR 碼相關的資訊或連結。

如何在 Android 快速設定中加入 QR 掃描器?

若要在快速設定中加入 QR 掃描器,請從 Android 裝置頂端向下滑動以開啟快速設定,點選「編輯」或鉛筆圖示,然後將 QR 掃描器磁磚拖曳到活動區域,以便快速存取。

在 Android 上掃描 QR 碼需要第三方應用程式嗎?

不一定。許多 Android 裝置都透過 Google Lens 或快速設定磁磚內建 QR 碼掃描功能。但是,如果您的裝置不支援這些功能,您可能需要第三方應用程式。

開發人員可以使用什麼函式庫在應用程式中加入 QR 碼功能?

開發人員可以使用 IronQR .NET 函式庫,將 QR 代碼的產生、讀取和處理功能加入其應用程式中,以實現進階的 QR 功能。

IronQR 可以用於 Android 應用程式開發嗎?

是的,IronQR 可以透過 Xamarin 或 .NET MAUI 等 Framework 整合至 Android 應用程式開發中,提供進階的 QR code 功能,例如產生和掃描。

IronQR 函式庫為開發人員提供哪些功能?

IronQR 提供的功能包括 QR 代碼產生、進階掃描功能、自訂選項、錯誤修正,以及支援各種資料類型的編碼。

開發人員如何將 IronQR 整合到他們的 Android 專案中?

開發人員可以使用 Xamarin 或 .NET MAUI 等 .NET Framework 將 IronQR 整合到 Android 專案中,啟用伺服器端 QR 代碼產生功能,或利用進階 QR 功能增強應用程式功能。

IronQR 是否有試用版?

是的,IronQR 提供免費試用版,讓開發人員在購買 Professional License 使用之前,可以探索其功能。

Jordi Bardia
軟體工程師
Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。