Getting Started - Android

The Android Capture client aims to make it as simple as possible to add scanning functionality into an Android application. It hides the complexity of the Android activity lifecycle by hooking into it. If you use a non-standard application architecture or just want more explicit control over the client and it’s lifecycle, please refer to the Java docs and create and manage an instance of :java:type:`CaptureClient` directly.

SDK Installation

The SDK is released as a NuGet package named SocketMobile.Capture. The NuGet package lies in a private GitLab package registry. Here you will find information on methods on how you can access the NuGet.

The Capture SDK NuGet depends on JSON NuGet from Newsoft that will get installed as well.

An application using the Socket Capture SDK needs to be registered in order to retrieve an AppKey that is required by the Capture API. You can register for an app key on the Socket Mobile Developer portal. Note you will have to log in to create an App Key.

Register to the Feed

The Package Registry will allow the user to have access to all packages and not just the most recent. To register to the package feed, you can use the following command line:

nuget source Add -Name "<package_source_identifier>" -Source "https://sdk.socketmobile.com/api/v4/projects/9/packages/nuget/index.json" -UserName <your_username> -Password <your_token>

<package_source_identifier>: An identifier of your choosing, e.g. “SecureRepo”. <your_username>: The provided Token identification. <your_token>: The provided Token.

You can also use a NuGet.config file. Either edit the global file or create a new one in the same directory of your solution to register to the package feed:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
            <add key="<package_source_identifier>" value="https://sdk.socketmobile.com/api/v4/projects/9/packages/nuget/index.json" />
    </packageSources>
    <packageSourceCredentials>
            <<package_source_identifier>>
                    <add key="Username" value="<your_username>" />
                    <add key="ClearTextPassword" value="<your_token>" />
            </<package_source_identifier>>
    </packageSourceCredentials>
</configuration>

Get the NuGet Package

Once registered, two main options can be used to get the NuGet package.

From your project’s directory, using the command line:

nuget install SocketMobile.Capture.Xamarin.iOS -Source "<package_source_identifier>"

Or directly using Visual Studio as you would with a NuGet from nuget.org. However, make sure that you have selected the newly added feed from the Package Manager.

Add package name

Use the same pacakge name that was previous used to register the application.

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="..."  package="YOUR_PACKAGE_NAME_HERE">
</manifest>

Targeting Android 28+?

Apps that target Android 28+ must also enable cleartext traffic to localhost. If you do not already have a network security configuration file, you will need to create one.

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="..." >
  <application android:label="..."
      android:networkSecurityConfig="@xml/network_security_config"
      ...>

  </application>
</manifest>
res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <base-config cleartextTrafficPermitted="false" />
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="false">localhost</domain>
    <domain includeSubdomains="false">127.0.0.1</domain>
  </domain-config>
</network-security-config>