Developer Hub
SupportDashboardGuides
Developer hub
Developer hub
  • Home
  • WiFi SDK
    • Overview
    • Integrating the SDK
      • iOS
        • QuickStart
        • SDK methods
          • initC4w
          • createCustomer
          • setupCustomer
          • createWPA2EnterpriseProfile
          • createPasspointProfile
          • getCreatedWPA2EnterpriseProfiles
          • getCreatedPasspointProfiles
          • getCustomerId
          • getCustomerInfo
          • updateCustomer
          • updateCustomerInfo
          • checkIfCustomerExists
          • getListOfPolicies
          • deletePasspointProfile
          • deleteWPA2EnterpriseProfile
          • setAPIAuthParams
          • setInterlinkedC4WIMobileSDKApplications
          • getInterlinkedC4WIMobileSDKApplications
          • logout
        • Objects
          • Customer
          • CustomerDocument
          • CustomerCreateResponse
          • CustomerInfo
          • CustomerQuery
          • WPA2EnterpriseProfile
          • PasspointProfile
        • Additional features
        • Changelog
      • Android
        • QuickStart
        • SDK methods
          • initC4w
          • createCustomer
          • setupCustomer
          • createWPA2EnterpriseProfile
          • deleteWPA2EnterpriseProfile
          • createPasspointProfile
          • deletePasspointProfile
          • isPasspointSupported
          • getCustomerId
          • getCustomerInfo
          • checkIfCustomerExists
          • updateCustomer
          • updateCustomerInfo
          • getListOfPolicies
          • setAPIAuthParams
          • getCreatedWPA2EnterpriseProfiles
          • getCreatedPasspointProfile
          • setInterlinkedC4WIMobileSDKApplications
          • getInterlinkedC4WIMobileSDKApplications
          • logout
        • Objects
          • Customer
          • CustomerDocument
          • CustomerCreateResponse
          • CustomerInfo
          • CustomerQuery
          • WPA2EnterpriseProfile
          • PasspointConfiguration
        • Additional features
        • Troubleshooting
        • Changelog
      • Flutter
        • QuickStart
        • Changelog
    • User experience
    • FAQ
  • Location SDK
    • Overview
    • Integrating the SDK
      • Android
        • Quickstart
        • Project initialization
        • SDK Methods
          • Enable/Disable
          • Handling blocking issues
          • Get Device Id
          • Reset device Id
          • Locations of Interest
            • Home location
            • Work location
        • Changelog
      • iOS
        • QuickStart
        • Installation
        • Project initialization
        • SDK methods
          • Initialization
          • Enable/Disable
          • Get Device Id
          • Reset device Id
          • Locations of interest
            • Home location
            • Work location
        • Reference versions
        • Changelog iOS
      • Flutter
        • QuickStart
        • Changelog
  • Demo toolkit
    • Demo app
    • Testlab WiFi setup
  • API Reference
    • Getting started
      • Authentication
      • Contacts
      • Locations
      • Geofences
      • Devices
      • Segments
      • WiFi logs
      • Events
    • Webhooks
    • Use cases
    • Legacy APIs (v2)
  • MyApps
    • My App Intro
    • Creating Apps
      • Access Journey Apps
      • Apps for the Dasbhoard
    • MyApps APIs and SDK
      • Access Journey SDK
      • REST APIs in MyApp
      • Context APIs
    • Sample projects
      • MyApps -Js SDK boilerplate
      • Video Advertising
      • Typeform integration
      • Facebook Pixel in Acces Journey
  • Tutorials
    • Sample onboarding flow for new app users
    • Integrating WiFi SDK in Flutter apps
Powered by GitBook
On this page
  • Integration
  • Configuration
  • Required permissions
  • Usage Example
  • Keep the customer update

Was this helpful?

Export as PDF
  1. WiFi SDK
  2. Integrating the SDK
  3. Android

QuickStart

Integration

To integrate SDK library into your Android project you need to add Cloud4Wi repository. After that add the following dependency to your project's build.gradle along with 3 dependencies required by Cloud4Wi SDK as described below:

repositories {

    ...
    
    maven {
        url = 'https://artifacts.cloud4wi.com/release'
    }
}

dependencies {

    ...

    implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.auth0.android:jwtdecode:2.0.0'    
    implementation 'com.cloud4wi:c4w-wifi-sdk:{lib-version}'
}

Configuration

In order to connect your application with your Cloud4Wi account, you need to provide SDK with clientKey and clientSecret credentials.

Credentials may be provided to SDK either via configuration property or at runtime. Add two records into your application's string.xml as in examples below:

<resources>
    ...
    <string name="com.cloud4wi.sdk.wifi.api_client_key">{client-key-value}</string>
    <string name="com.cloud4wi.sdk.wifi.api_client_secret">{client-secret-value}</string>
</resources>

Add the following in 'application' section of your AndroidManifest.xml file:

<application>
 ...
 <provider
           android:authorities="${applicationId}"
           android:multiprocess="false"
           android:exported="false"
           android:name="com.cloud4wi.sdk.wifi.storage.C4WIMobileSDKContentProvider"/>
</application>

Required permissions

AndroidManifest of this library requires following permissions

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Usage Example

In following code example we will create new customer in the API and then install WPA2-Enterprise Wi-Fi profile on Android phone. After that when customer will be in range of Wi-Fi network with specified SSID - his device will connect automatically.

This example represents following use-case.

  1. MobileSDK configuration. Setting API client credentials.

  2. Read list of organization policies from API.

  3. Creating new customer in API.

  4. Verifying customer credentials in API.

  5. Creation of WPA2-Enterprise Wi-Fi profile on Android device for test user to connect to test SSID.

Cloud4WiSDKWiFi mobileSDK = new Cloud4WiSDKWiFi(getApplicationContext());

        try {
            mobileSDK.setAPIAuthParams("{client-key-value}", "{client-secret-value}");
        } catch (Exception e) {
            Log.e(TAG, "Cannot set API credentials: ", e);
        }

        mobileSDK.updateCustomerInfo(result -> {}, e -> {});
        /*
         * To register new customer we need to obtain required polices from API Server
         */
        mobileSDK.getListOfPolicies(
                policies -> {
                    Log.i(TAG, "Got policies. Num = " + policies.size());
                    logInfo("Got " + policies.size() + " policies: ");
                    for (String p : policies) {
                        logOutput("  " + p);
                    }

                    Customer customer = new Customer();
                    customer.setFirstName("Test");
                    customer.setLastName("Customer");
                    customer.setEmail(customer.getUsername());

                    /*
                     * In order to register new customer all polices requested by API Server should be accepted
                     */
                    for (String policy : policies) {
                        customer.addPolicy(policy, true);
                    }

                    /*
                     * Call Server API to create new customer
                     */
                    mobileSDK.createCustomer(customer, null,
                            customerCreateResponse -> {
                                Log.i(TAG, "Customer successfully created.");
                                logInfo("Customer successfully created.");

                                /*
                                 * Assure new customer has been successfully created via Server API by checking newly created customer's credentials
                                 * This step is OPTIONAL
                                 */
                                    mobileSDK.getCustomerInfo(customerCreateResponse.getUsername(), customerCreateResponse.getPassword(),
                                            customerInfo -> {
                                                Log.i(TAG, "Credentials approved.");
                                                logInfo("Credentials approved.");

                                                /*
                                                 * Here we are calling Android API to create WPA2-Enterprise Wi-Fi Profile for recently created new customer
                                                 */
                                                mobileSDK.createWPA2EnterpriseProfile(customerCreateResponse.getUsername(), customerCreateResponse.getPassword(),
                                                        wpa2EnterpriseProfile -> {
                                                            Log.i(TAG, "Wi-Fi profile successfully created.");
                                                            logInfo("Wi-Fi profile successfully created.");
                                                        },
                                                        e -> {
                                                            Log.e(TAG, "Failed to create Wi-Fi profile: ", e);
                                                            logError("Failed to create Wi-Fi profile: " + e.getMessage());
                                                        });
                                            },
                                            e -> {
                                                Log.e(TAG, "Cannot approve credentials: ", e);
                                                logError("Cannot approve credentials - " + e.getMessage());
                                            }
                                    );
                            },
                            e -> {
                                Log.e(TAG, "Cannot create customer: ", e);
                                logError("Cannot create customer - " + e.getMessage());
                            }
                    );
                },
                e -> {
                    Log.e(TAG, "Cannot get policies: " +  e.getMessage());
                    logError("Cannot get policies - " + e.getMessage());
                }
        );

Keep the customer update

To track the last seen date of the customer and to keep always updated the remote push notification token (if applicable) it is necessary to call the method every time the app starts

public void initC4w();
PreviousAndroidNextSDK methods

Last updated 7 months ago

Was this helpful?