Create a Barcode Scanner App in just 3 Minutes with Xamarin.Forms

So few weeks back my boss tasked me to implement a barcode scanning feature in one of our enterprise mobile apps which we were building using Xamarin Cross Platform. I got freaked out, as I have never implemented anything related to barcode scanning, not even in my 3 years of Windows Phone dev experience :P ! I was worrying whether it would get much messier when it comes to Cross Platform development.😦

But luckily I was able to implement the task under 15 mins, thanks to the awesomeness of Xamarin. I came across this epic library called ACR Barcodes Plugin for Xamarin Forms, which allowed me to easily implement the code bar code scanning and reading feature.

So with that experience, now I’m gonna show you how you could build a Barcode Scanner App in just 3 Minutes..😀 Prepare to be mind blown !😉

First create a Xamarin.Forms project (PCL project) solution in Visual Studio and add the  ACR Barcodes Plugin using nuget package manager.

Simple implementing in your PCL…

Create a new class in your PCL project called Page_BarcodeScanner. And replace that Class code with the following code.

class Page_BarcodeScanner : ContentPage
	public Page_BarcodeScanner() 
		Button btnScan = new Button
			Text = "Scan Barcode",
			HorizontalOptions = LayoutOptions.FillAndExpand,

		btnScan.Clicked += async (a, b)   => 

		this.Content = new StackLayout
			Children = 

	#region Scan Barcode
	async void Launch_BarcodeSearch()
		var result = await BarCodes.Instance.Read();
		if (!result.Success)
			await this.DisplayAlert("Sorry ! Scan Failed ! ", "Sorry ! Failed to read the Barcode !", "OK");                
			var msg = String.Format("Barcode Format : {0} \n Barcode Value : {1}", result.Format, result.Code);
			await this.DisplayAlert("Scan Successful !", msg, "OK");



Now resolve the necessary imports…😉 And you just created the Bar code scanner code. So let’s set this page to be executed in the App.cs file. Open up the App.cs code file in the PCL project and replace its App() method with the following.

public App()
	// The root page of your application
	MainPage = new Page_BarcodeScanner();


There you go, but wait… Just a little bit more configuring to be done.😉

Now we have to set the camera access permission and initiate the library on Android/ iOS and WinPhone projects. Nothing to worry its pretty simple.

Setting up on Android..

In your Android project, replace the OnCreate method in the MainActivity.cs code file with the following. This init()  call will initialize the library for the application.

protected override void OnCreate(Bundle bundle)

	global::Xamarin.Forms.Forms.Init(this, bundle);
	BarCodes.Init(() => (Activity)Forms.Context);
	LoadApplication(new App());


Now we need to set the permission for the app to access the Camera on the device, so double click on Properies -> select tab  Android Manifest -> Tick on CAMERA permission.


That’s it ! Now you can even set your Android project as the default project and run the application successfully..😉  or else you could go ahead with the rest of the configuration on iOS and WinPhone..😀

Setting up on iOS…

In you iOS app, replace the FinishedLaunching() method in the AppDelegate.cs code file with the following code, in order to initialize the library for the usage of the application.

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
	LoadApplication(new App());

	return base.FinishedLaunching(app, options);


That’s it, oh and not to worry you don’t have to set the permission on the iOS project.😉

Setting up on Windows Phone…

Finally on Windows Phone Project (WinPhone) replace the MainPage() constructor in the MainPage.xaml.cs file with the following code,

public MainPage()
	SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;

	LoadApplication(new EasyBarcodeReaderApp.App());


Now let’s set the camera permission on Windows Phone as follows…

Expand Properties -> Double click on WMAppManifest.xml -> Go to Capabilities tab -> Tick on ID_CAP_ISV_CAMERA permission


Finally thats it !😀 Now you can build the whole project and run the app in any selected platform as you wish…😀


Below are some screenshots I took after I deployed in my Windows Phone device.🙂 Now its all up to you to make any necessary improvements or implement this in any of your awesome apps as you wish.😉

wp_ss_20150520_0002 wp_ss_20150520_0003 wp_ss_20150520_0005

Keep up the awesomeness ! ^_^

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s