Prerequisites – What you need to get started

  • A Nexus Account: our SDK is available on a private Nexus. Your account details have been communicated to you by email.
  • Your SDK credentials, including an SDK Login, Password, and Company Key to initialize the SDK.
  • A QR Code and an NFC Tag: you need a QR CODE and an NFC Tag set up on your Adtag Account to test the application
  • An Android Device: an Android device with camera and an NFC reader.
  • The Android Studio application, which you can download from the Android Developers website.

Step 1: Clone the sdk-tutorial repository

  • Clone the sdk-tutorial repository
git clone https://github.com/Connecthings/sdk-tutorial.git

Step 2: Launch QrNfcDemo in Android Studio

  • Launch Android Studio

  • Check that your Android SDK is up to date.

    • Click on Tools > Android > SDK Manager
    • Inside the SDK Platform tab, check that Android 6 has been correctly installed
    • Inside the SDK Tools tab, check that the Android Tools, the Android Support Library, and the various Google Services have all been correctly installed
  • In the Android Studio Wizzard, click on import project.

  • Or, if you already are inside an Android Studio project, go to "File > Open"

  • Select the android>qrNfc>qrNfcDemo folder from the cloned sdk-tutorial folder
  • Open the ApplicationSdkDemo class
  • Configure AdtagInitializer on the Production platform, with the information you received from Connecthings:
      AdtagInitializer.initInstance(this)
                      .initUrlType(UrlType.PROD)
                      .initUser("YOUR_USER",  "YOUR_PWD")
                      .initCompany("YOUR_COMPANY_KEY");
  • Check that your Android Device is in Developer Mode
  • Connect your Android Device to your computer
  • In Android Studio, click on "Play" to launch the installation process on your phone
  • QrNfcDemo launches automatically

QrNfcDemo and its two activities

QrNfcDemo contains two activities:

  • ActivityQrNfcFgOnly: demonstrates interactions with QR codes and NFC tags only when the application is in the foreground of the user’s device
  • ActivityQrNfcFgBg: demonstrates interactions with QR codes and NFC tags when the application is either in the foreground or in the background

The code of both activities is identical: ActivityQrNfcFgBg is simply an extension of ActivityQrNfcFgOnly.

However, the Manifest configuration for both activities is different: the ActivityQrNfcBg class declares two additional intent-filters, which enable it to take control of Android’s default actions to read QR codes and NFC tags.

Testing ActivityQrNfcFgOnly

  • Launch the QrNfcDemo activity
  • Click on Activity Foreground only interactions

Test a QR Code

  • Click on Flash QR with default Activity
  • Flash the QR Code you received from Connecthings
  • A new page opens (entitled ActivityContent): it displays the name of the point associated to the QR Code

Test an NFC Tag

  • Place your phone on the NFC Tag you received from Connecthings: you must find the specific place where your phone interacts with NFC tags (NFC readers can be placed anywhere depending on the model of your phone)
  • A new page opens (entitled ActivityContent): it displays the name of the point associated to the NFC Tag (normally the same point that for the QR Code)

Testing ActivityQrNfcFgBg

Test a QR Code

  • Quit or kill the QrNfcDemo application
  • Install an external application to flash your QR Code. We recommend:
    • BarCode Scanner
    • Enigma
  • When the application is installed, launch it and flash the QR code you received from Connecthings.
  • The application asks you to choose between two applications:
    • the Chrome browser
    • the QRNfcDemo application
  • Select QRNfcDemo
  • ActivityQrNfcFgBg is launched: this triggers a connection with the Adtag platform to retrieve the content corresponding to the QR code. Once the content is retrieved, ActivityContent automatically opens.

Test an NFC Tag

  • In QrNfcDemo, open the manifest file.
  • Quit or kill the QrNfcDemo application
  • Place your phone on the NFC Tag you received from Connecthings
  • The phone asks you to choose between two applications:
    • the Chrome browser
    • the QRNfcDemo application
  • Select QRNfcDemo

ActivityQrNfcFgBg is launched: this triggers a connection with the Adtag platform to retrieve the content corresponding to the NFC tag. Once the content is retrieved, ActivityContent automatically opens.

Switching from the Production to the Pre-production Platform

  • Open the ApplicationSdkDemo class
  • Update the AdtagInitializer on the pre-production platform (PRE_PROD) with the information you received from Connecthings:
  AdtagInitializer.initInstance(this)
                  .initUrlType(UrlType.PRE_PROD)
                  .initUser("YOUR_USER_PREPROD",  "YOUR_PWD_PREPROD")
                  .initCompany("YOUR_COMPANY_KEY");
  • Update the manifest configuration for ActivityQrNfcFgBg
    • You must update the <data android:host="t.adtag.fr" />
  • Replace t.adtag.fr with t-preprod.adtag.fr

Warning:

Android:host appears on two different lines of code: do not forget to update both lines.

Note:

The AdtagInitializer permits to configure the access to the various Adtag platforms. Connecthings gives you access to three platforms :

  • The Demo platform is ideal for the technical Proof of Concept (POC) phase
  • The Pre-production platform is ideal for the beta versions
  • The Production platform is used when you're ready to publish your application

Warning 1:

Be sure to use the good access key login / password with the appropriate platform - for each platform (Demo/Pre-production/Production) you have received a specific access key.

Warning 2:

Connecthings sends you a user to connect to the Adtag Platform and a user with an API KEY to be used with the SDK. Be sure to use the user with the API KEY to connect the SDK to the Adtag Platform, otherwise the application won't detect the beacons.

Warning 3:

Connecthings sends you two different access keys for each platform: - An access key to sign in the Adtag Platfrom - An access key to use with the mobile SDK, called API_KEY. Be sure to use the correct API KEY (login, password, and platform) to connect the SDK to the Adtag Platform, otherwise the application won't detect the beacons.