How to get rawdata from DataWedge on App with Xamarin ?

2 years 11 months ago
67 1 0

I building App on Xamarin.Forms.
 
How to get rawdata from Datawedge on App with Xamarin ?
 
I use Broadcastreceiver and Intent Action.
 
DATA_STRING_TAG -> GetStringExtra
 
DECODE_DATA_TAG -> ???
 
Thank you.

Please register or login to post a reply

1 Replies

V Vedsatx Saddvv

I have not used Xamarin Forms yet,  but the below works in a regular Xamarin app.  I have also attached the whole project in case that helps.

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Java.IO;

namespace DwMultiActivity
{
    [Activity(Label = "DwMultiActivity", MainLauncher = true, Icon = "@drawable/icon", LaunchMode = Android.Content.PM.LaunchMode.SingleInstance)]
    public class MainActivity : Activity
    {
        private static String SOURCE_TAG = "com.symbol.datawedge.source";
        private static String DATA_STRING_TAG = "com.symbol.datawedge.data_string";
        private static String LABEL_TYPE_TAG = "com.symbol.datawedge.label_type";
        private static TextView tvScanData;
        Button btnScan;
        private handleBarcode mHandleBarcode;

        private static Button btnNextActivity;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            installDwProfile();

            mHandleBarcode = new handleBarcode();
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            tvScanData = FindViewById(Resource.Id.tvScanData);
            TextView tvAct = FindViewById(Resource.Id.tvCurrentActivity); //this is just to show which activity is on the screen
            tvAct.Text = this.ComponentName.ShortClassName.Split('.')[1];  //this is just to show which activity is on the screen
            btnScan = FindViewById(Resource.Id.btnScan);
            btnNextActivity = FindViewById(Resource.Id.btnNextActivity);
            btnScan.Click += delegate
            {
                Intent i = new Intent();
                i.SetAction("com.symbol.datawedge.api.ACTION_SOFTSCANTRIGGER");
                i.PutExtra("com.symbol.datawedge.api.EXTRA_PARAMETER", "START_SCANNING");
                this.SendBroadcast(i);
            };

            btnNextActivity.Click += delegate
            {
                StartActivity(typeof(Activity2));
            };
        }

        protected override void OnResume()
        {
            IntentFilter filter = new IntentFilter("com.zebra.silva.dwmultiactivityexample.RECVR");
            RegisterReceiver(mHandleBarcode, filter);
            base.OnResume();
        }
        protected override void OnPause()
        {
            UnregisterReceiver(mHandleBarcode);
            base.OnPause();
        }

        public void installDwProfile()
        {
            // copy datawedge profile from assets to autoimport folder on device.  This should only need to be done once enless someone actually removes the profile in datawedge
            var tempPath = "/enterprise/device/settings/datawedge/dwprofile_DwMultiActivityTest.db"; // copy it here first and fix permissions before moving to autoimport
            var filePath = "/enterprise/device/settings/datawedge/autoimport/dwprofile_DwMultiActivityTest.db";

            using (var asset = Assets.Open("dwprofile_DwMultiActivityTest.db")) using (var dest = System.IO.File.Create(tempPath))
                asset.CopyTo(dest);        
            Java.IO.File file1 = new File(tempPath);
            file1.SetReadable(true, false);
            file1.SetWritable(true, false);
            System.IO.File.Move(tempPath, filePath);
        }

        public class handleBarcode : BroadcastReceiver
        {

            public override void OnReceive(Context context, Intent i)
            {
                // define a string that will hold our output
                //String out = new String();
                // get the source of the data
                String sSource = i.GetStringExtra(SOURCE_TAG);
                // save it to use later
                if (sSource == null) sSource = "scanner";
                // get the data from the intent
                String sData = i.GetStringExtra(DATA_STRING_TAG);
                // let's define a variable for the data length
                int data_len = 0;
                // and set it to the length of the data
                if (sData != null) data_len = sData.Length;
                // check if the data has come from the barcode scanner
                if (sSource.ToLower().Equals("scanner"))
                {
                    // check if there is anything in the data
                    if (sData != null && sData.Length > 0)
                    {
                        // we have some data, so let's get it's symbology
                        String sLabelType = i.GetStringExtra(LABEL_TYPE_TAG);
                        String temp = sSource + ":" + sLabelType + ":" + sData;
                        tvScanData.Text = sSource + ":" + sLabelType + ":" + sData;
                    }
                }

            }
        }

    }
}

CONTACT
Can’t find what you’re looking for?