Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
vodela
Active Participant
0 Kudos

In Any Mobile Application that is built on SAP the ability to have barcode support is very important as this saves time and helps improve efficiency.  I have developed a Procure to Pay application using Xamarin Forms

http://scn.sap.com/community/developer-center/mobility-platform/blog/2014/07/31/c-cross-platform-mob...

As soon as I was done this the first request I get is to add BarCoding Support.  This Blogs describes on how to add Barcoding Support for a mobile application that is developed using Xamarin Forms.  If my application I have Create PO Option,  When the user selects this option, the application allows you to enter header info and when you Click on Add PO Lines Buttons - you can enter any number of PO Lines, To this screen I added a button to scan Material Barcode

When the user Clicks on this A Material BarCode is scanned and displayed in the Material Text Field on the screen

Code Explanation

when you create a Xamarin Forms Mobile Application in Visual Studio - it Creates 4 projects one is PCL project which is common to all 3 platforms and one project each for 3 Mobile Devices(IOS,Andorid,WP).

In the PCL Project I create an interface

public interface IBarCodeScan

  {        Task ScanBarCode();    }

In Each of the Platform specific projects(IOS,,Andorid) there is folder called components - Here you can right click and choose Add more components and choose ZXING( do this for both projects) In each of the projects each a Folder and implement the interface that is specific to the Device

using ZXing.Mobile; using ZXing;

using Xamarin.Forms; using sapp2p.Droid.PaltformSpecific; [assembly: Dependency(typeof(BarCodeScan))]

public class BarCodeScan : IBarCodeScan

  {        async System.Threading.Tasks.Task IBarCodeScan.ScanBarCode()  

    {            var scanner = new MobileBarcodeScanner(Forms.Context) { UseCustomOverlay = false };    

      var result = await scanner.Scan();        

  return result.ToString();        }    }

The statement [assembly: Dependency - In PCL project you  have the interface by which you invoke the Scan method - the Assembly statement ensures that the call from PCL is linked to the device specific call based on which device the app is running. In the PCL project  - the page with PO Lines - Scan Button

Click I add the following line public async Task ScanBarCode()      

{            _mATNR = await DependencyService.Get().ScanBarCode();          

RaisePropertyChanged(() => MATNR);        }

Of course you had Camera Permission to the Manifest(in the android specific project properties)

For Windows phone you have to right Click on Reference and choose Nuget to add the ZHING component .

Labels in this area