SocketCam¶
The C# Capture SDK now has support for SocketCam C820 on Android and iOS. It does not yet have support for C860 but this will be added in a future release.
The application receives the decoded data with the same APIs that are used for physical readers and they can also be used to manage some of the SocketCam properties the same way you would for a physical reader. To unable SocketCam, extra steps are required and listed below.
Android¶
Add your credentials in the AndroidManifest.xml inside <application></application>:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="...">
<application android:label="..." android:networkSecurityConfig="@xml/network_security_config" android:theme="...">
<meta-data android:name="com.socketmobile.capture.APP_KEY" android:value="<YourAppKey>" />
<meta-data android:name="com.socketmobile.capture.DEVELOPER_ID" android:value="<YourDeveloperId>" />
</application>
</manifest>
The Android application context should be set before opening the Capture Helper. It can be achieved by using an instance of CaptureHelper in the MainActivity.cs:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
CaptureHelper capture = new CaptureHelper();
capture.SetAndroidContex(this);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
Note
This example is from XamarinApp.Android, the same code can be applied in Maui under Platforms->Android->MainActivity.cs
iOS¶
Under Xamarin all the code to open the Capture Helper, register for events and manipulate properties should be under the Xamarin.iOS app.
Note
The Xamarin SampleApp uses Dependency Services to link the platform specific code.
Both on Android and iOS¶
Once you are connected you should set the SocketCam status to Enable:
CaptureHelper capture = new CaptureHelper();
capture.SetSocketCamStatusAsync(CaptureHelper.SocketCamStatus.Enable);
After the device arrival you should set the overlay view using the recieved device as
reference with the SetSocketCamOverlay()
method:
private void Capture_DeviceArrival(object sender, CaptureHelper.DeviceArgs e)
{
DeviceEventText = string.Format("Device Arrival: {0}", e.CaptureDevice.GetDeviceInfo().Name);
// Last device arrival is the new selected device
selectedDevice = e.CaptureDevice;
// Set SocketCam Overlay to display camera
MainThread.BeginInvokeOnMainThread(async () =>
{
var getStatus = await capture.GetSocketCamStatusAsync();
if (getStatus.Status == CaptureHelper.SocketCamStatus.Enable) selectedDevice.SetSocketCamOverlay();
});
}
Note
The GetSocketCamStatusAsync() method is used to retrieve the SocketCam status and can be applied to initialize a toggle switch or make sure to not Enable or Disable SocketCam twice. It is recommended to use await to wait for the returned value.
Since SocketCam is not an independent device, a scan trigger button should be added:
private void Button_TriggerScan(object sender, EventArgs e)
{
selectedDevice.SetTriggerStartAsync();
}