This example client side application demonstrates how to integrate client side library with server side library.

Download button

Configuring the client side library

Important. Your client side library will work only with server side library. Available server side libraries: .Net , PHP, Java

  1. Download the Mobile Connect client side library.

    git clone https://github.com/Mobile-Connect/android_client_side_library.git
  2. Open project in Android Studio.
  3. Download and install any missing dependencies or plugins from the links displayed in the console output.
  4. Build the project.
  5. Open the configuration file: /local-path/Application/src/main/res/values/configuration.xml.
    Here are the following parameters:
        <string name="server_endpoint_with_discovery_endpoint">your server side endpoint for demo with discovery</string>
        <string name="server_endpoint_without_discovery_endpoint">your server side endpoint for demo without discovery</string>
        <string name="msisdn">default msisdn</string>
        <string name="msisdn_wd">default msisdn for without discovery mode</string>
        <string name="mcc_value">default mcc</string>
        <string name="mnc_value">default mnc</string>
  6. Be sure to provide your server_endpoint_with_discovery_endpoint (endpoint of your server side library).
    You can also configure your msisdn, mcc and mnc if it's necessary.
    If you are using 'Without Discovery' mode you should provide server_endpoint_without_discovery_endpoint and msisdn_wd
  7. Add your custom configuration (e.g. ip_address) if it is necessary.

Using the client side library

Using With Discovery Demo

With your configuration specified in the configuration file or using user interface, you have everything you need to make a successful call to the server-side library.
You can use client side application in three modes:

  • Using msisdn
  • Using mcc_mnc
  • None mode

Also you can add IP address to the request to server side.
After you clicking Mobile Connect button the Application:

  1. Checks which mode you have selected.
  2. Checks that configuration of your selected mode is valid.
  3. Makes startDiscoverySession method from SessionHandler call into the library with your configuration in parameters:
    public void startDiscoverySession(Context context, String msisdn, String mcc, String mnc, String ipAddress, String serverSideWithoutDiscoveryEndpoint) {
            List<NameValuePair> params = HttpUtils.prepareParameters(msisdn, mcc, mnc, ipAddress);
            final String requestUrl = HttpUtils.createGetWithParams(serverSideWithoutDiscoveryEndpoint, params);
            MobileConnectView mobileConnectView = new MobileConnectView();
            mobileConnectView.startAuthentication(context, requestUrl);
        }

    This method generates GET request to the server side endpoint (from your configuration). To generate the request parameters it uses prepareParameters method:
    private List<NameValuePair> prepareParameters(String msisdn, String mcc, String mnc, String ipAddress) {
            List<NameValuePair> params = new LinkedList<>();
            if (!StringUtils.isNullOrEmpty(msisdn)) {
                params.add(new BasicNameValuePair(Constants.MSISDN, msisdn));
            } else if (!StringUtils.isNullOrEmpty(mcc) && !StringUtils.isNullOrEmpty(mnc)) {
                params.add(new BasicNameValuePair(Constants.MCC, mcc));
                params.add(new BasicNameValuePair(Constants.MNC, mnc));
            }
            if (!StringUtils.isNullOrEmpty(ipAddress)) {
                params.add(new BasicNameValuePair(Constants.SOURCE_IP, ipAddress));
            }
            return params;
        }

    After having prepared a request URI the application sends GET request by passing the request URL into the WebView:
    MobileConnectView mobileConnectView = new MobileConnectView();
            mobileConnectView.startAuthentication(getContext(), requestUrl);
    .
    • If you are using only msisdn the request to your server side part will be: http://server_side_endpoint?msisdn=your_msisdn.
    • When you are using mcc and mnc it will be: http://server_side_endpoint?mcc=your_mcc&mnc=your_mnc.
    • If you choose None mode: http://server_side_endpoint.
    • Also you can check IP address e.g. in msisdn mode: http://server_side_endpoint?msisdn=your+msisdn&ip_address=your_ip_address.
  4. In case of failure while sending the request to server side, the result is displaying in the WebView or using Toast messages.

  5. After displaying web view:
    • In msisdn mode you will see a few redirects until the web view gets the URL with code and state parameters.
    • Using mcc_mnc or none mode you will be redirected to the operator selection page. Here you can type your msisdn and process page.

    In any case after getting URL with code and state parameters application sends GET request (to the server side) by opening this URL and gets the response with JSON, that contains the results information. After getting the response the application closes the WebView and shows 'Dialog Closed' message. AuthenticationWebViewClient watches URL's in web view dialog using shouldOverrideUrlLoading method:

        @Override
        public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
            super.shouldOverrideUrlLoading(view, url);
            Log.i(TAG, String.format("Loading URL=%s", url));
            this.progressBar.setVisibility(View.VISIBLE);
            if (url.contains(Constants.CODE_PARAM) && url.contains(Constants.STATE_PARAM)) {
                view.loadUrl(url);
                Toast.makeText(view.getContext(), view.getContext().getString(R.string.dialog_closed), Toast.LENGTH_SHORT).show();
                return true;
            } else if (url.contains(Constants.ERROR_PARAM)) {
                String error = Uri.parse(url).getQueryParameter(Constants.ERROR);
                String errorDescription = getErrorStatus(url);
                Log.w(TAG, String.format("Error while authorisation session: %s - %s", error, errorDescription));
                dialog.cancel();
                Toast.makeText(view.getContext(), String.format("Error occurred while authorisation session: %s, %s", error, errorDescription), Toast.LENGTH_SHORT).show();
                return true;
            } else {
                view.loadUrl(url);
                return false;
            }
        }

Using Without Discovery Demo

You can configure using two ways MSISDN for 'Without Discovery' mode that will be included into the request to server-side:
1. Using configuration.xml file by changing msisdn_wd
2. While Application is running by typing.

After you clicking Mobile Connect button the Application makes startWithoutDiscoverySession(String msisdn) method from SessionHandler call with your MSISDN into the parameter.
This method generates GET request to the server side without discovery endpoint (from your configuration: server_endpoint_without_discovery_endpoint).

    public void startDiscoverySession(Context context, String msisdn, String mcc, String mnc, String ipAddress, String serverSideWithoutDiscoveryEndpoint) {
        List<NameValuePair> params = HttpUtils.prepareParameters(msisdn, mcc, mnc, ipAddress);
        final String requestUrl = HttpUtils.createGetWithParams(serverSideWithoutDiscoveryEndpoint, params);
        MobileConnectView mobileConnectView = new MobileConnectView();
        mobileConnectView.startAuthentication(context, requestUrl);
    }

After generation of the request URI the application sends GET request by passing the request URL into the WebView:
MobileConnectView mobileConnectView = new MobileConnectView();
        mobileConnectView.startAuthentication(getContext(), requestUrl);
.
The request to your server side part has the following format: http://server_endpoint_without_discovery_endpoint?msisdn=your_msisdn_wd.

In any case after getting URL with code and state parameters application sends GET request (to the server side) by opening this URL and gets the response with JSON, that contains the results information. After getting the response the application closes the WebView and shows 'Dialog Closed' message. AuthenticationWebViewClient watches URL's in web view dialog using shouldOverrideUrlLoading method:

    @Override
    public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
        super.shouldOverrideUrlLoading(view, url);
        Log.i(TAG, String.format("Loading URL=%s", url));
        this.progressBar.setVisibility(View.VISIBLE);
        if (url.contains(Constants.CODE_PARAM) && url.contains(Constants.STATE_PARAM)) {
            view.loadUrl(url);
            Toast.makeText(view.getContext(), view.getContext().getString(R.string.dialog_closed), Toast.LENGTH_SHORT).show();
            return true;
        } else if (url.contains(Constants.ERROR_PARAM)) {
            String error = Uri.parse(url).getQueryParameter(Constants.ERROR);
            String errorDescription = getErrorStatus(url);
            Log.w(TAG, String.format("Error while authorisation session: %s - %s", error, errorDescription));
            dialog.cancel();
            Toast.makeText(view.getContext(), String.format("Error occurred while authorisation session: %s, %s", error, errorDescription), Toast.LENGTH_SHORT).show();
            return true;
        } else {
            view.loadUrl(url);
            return false;
        }
    }