I have a problem using the library Zxing,Net.Mobile, want to have a popup (fragment) which reads a barcode, but in debug I get an error, I'm using the following repository as an example (https://github.com/Redth/ZXing.Net.Mobile/tree/master/Samples/Sample.Android), but when I run the code and click to open the fragment I get the following problem.
This is my AXML Activity (OrdersPatientsActivity)
When I click on the red highlighted button, it opens my popup (ScanBarcodeFragment), but in the Activity I initialise Zxing as follows (the final part):
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.LayoutListOrdenPatient);
searchBar = FindViewById<EditText>(Resource.Id.searchBarMainFilterCarMed);
llPatientInfo = FindViewById<LinearLayout>(Resource.Id.llPatientInfo);
PatientName = FindViewById<TextView>(Resource.Id.tvPatientNameCarMed);
IdentificationType = FindViewById<TextView>(Resource.Id.tvTDocumentoCarMed);
Identification = FindViewById<TextView>(Resource.Id.tvDocumentoCarMed);
Age = FindViewById<TextView>(Resource.Id.tvEdadCarMed);
HistoryNumber = FindViewById<TextView>(Resource.Id.tvHistoriaCarMed);
EntryNumber = FindViewById<TextView>(Resource.Id.tvNoIngresoCarMed);
Location = FindViewById<TextView>(Resource.Id.tvUbicacionCarMed);
btnExpandView = FindViewById<ImageButton>(Resource.Id.btnExpandView);
btnScanMed = FindViewById<ImageButton>(Resource.Id.btnScanMed);
ListMedicamentCarMed = FindViewById<ListView>(Resource.Id.ListMedicamentCarMed);
Save = FindViewById<Button>(Resource.Id.btnGuardar);
///vista cargando
var ProgressView = LayoutInflater.Inflate(Resource.Layout.LoadingDialogCharge, null);
TextView Msg = ProgressView.FindViewById<TextView>(Resource.Id.tvProgressDialogMsg);
Msg.Text = "Cargando información de los cargos...";
animationscale = AnimationUtils.LoadAnimation(this, Resource.Drawable.Animationlogo);
LogoDialogProgress = ProgressView.FindViewById<ImageView>(Resource.Id.LogoDialogProgress);
progressDialog = (new AlertDialog.Builder(this, Resource.Style.ServinteDialog)).Create();
progressDialog.SetView(ProgressView);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);
btnScanMed.Click += BtnScanMed_Click;
}
Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); ZXing.Net.Mobile.Forms.Android.Platform.Init(); ZXing.Mobile.MobileBarcodeScanner.Initialize(Application);
And in the click the ImageView is this:
try
{
StartActivity(typeof(ScanBarcodeFragment));
}
the fragment is exactly as in the example:
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZXing.Mobile;
namespace APPDroid.CarMed.Fragments
{
[Activity(Label = "ZXing.Net.Mobile", Theme = "@style/Theme.AppCompat.Light", ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.KeyboardHidden)]
public class ScanBarcodeFragment : AndroidX.Fragment.App.FragmentActivity
{
#region Variables
ZXingScannerFragment scanFragment;
#endregion
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.ScanBarcode);
}
protected override void OnResume()
{
base.OnResume();
if (scanFragment == null)
{
scanFragment = new ZXingScannerFragment();
SupportFragmentManager.BeginTransaction().Replace(Resource.Id.fragment_container, scanFragment).Commit();
}
Scan();
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
=> Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
protected override void OnPause()
{
scanFragment?.StopScanning();
base.OnPause();
}
void Scan()
{
var opts = new MobileBarcodeScanningOptions
{
PossibleFormats = new List<ZXing.BarcodeFormat> {
ZXing.BarcodeFormat.QR_CODE
},
CameraResolutionSelector = availableResolutions =>
{
foreach (var ar in availableResolutions)
{
Console.WriteLine("Resolution: " + ar.Width + "x" + ar.Height);
}
return null;
}
};
scanFragment.StartScanning(result =>
{
// Null result means scanning was cancelled
if (result == null || string.IsNullOrEmpty(result.Text))
{
Toast.MakeText(this, "Scanning Cancelled", ToastLength.Long).Show();
return;
}
// Otherwise, proceed with result
RunOnUiThread(() => Toast.MakeText(this, "Scanned: " + result.Text, ToastLength.Short).Show());
}, opts);
}
}
}
But I get this error when I click on it:
when inflating the view all goes well, but when finishing the Scan() method; the problem occurs:
Android.Content.Res.Resources+NotFoundException Message=Resource ID #0x7f0a002a
Is it possible that I need an extra textview with a result ID?
Please I need help I have been trying to do barcode scanning for several days.