User ID in a WebView

 

Foreword

If your application must use a WebView and you wish to identify the user, you can retrieve the customer ID in order to then pass it in a URL parameter of your WebView. By doing so, you can use this ID with JavaScript code, for example.

As this method is asynchronous, you must implement the callback when the data is exploitable.

package com.atinternet.atinternetdemo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.atinternet.tracker.ATInternet;
import com.atinternet.tracker.Tracker;
import com.atinternet.tracker.UserIdCallback;


public class MainActivity extends Activity {

    private Tracker tracker;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tracker = ATInternet.getInstance().getDefaultTracker();
    }

    @Override
    protected void onResume() {
        super.onResume();
        tracker.getUserId(new UserIdCallback() {
            @Override
            public void receiveUserId(String id) {
                Log.d(null, "Current idclient is : " + id);
                // Start your Web view here
            }
        });
    }
}

Since 2.3.0, equivalent sync method is available (Warning : it’s required to send a first hit before using it. On the contrary, a warning is sent by the SDK)

@Override
protected void onResume() {
    super.onResume();
    tracker.getUserIdSync();
}
Last update: 05/04/2018