Richard Matovu
Richard Matovu

Reputation: 511

How to get the device fingerprint

I am trying to integrate a payment API in my application and one of the required field is the device fingerprint. I have googled and all I got was the fingerprint scanner and touch Id support which aren't what I need. Any ideas?

Upvotes: 2

Views: 3197

Answers (1)

Francesco Galgani
Francesco Galgani

Reputation: 6249

Realistically speaking, perhaps the simplest thing you can do is not to obtain or calculate a unique device identifier, but to assign each specific installation of your app a unique code (which will therefore change if the app is uninstalled and reinstalled).

I'll try to give you an example.

In the init() method of the main class, you can add this code:

// Register the device (assigning it an unique deviceId)
// The deviceId is used also by: https://www.codenameone.com/javadoc/com/codename1/io/Util.html#getUUID--
registerDevice();

Your registerDevice() implementation could set the deviceId to identify this app installation. The best and most reliable solution, in this case, is to get a UUID from your server, e.g. like this code:

// Sets the device unique identifier
Rest.get(Server.getRestServerURL() + "/uniqueIdentifier").fetchAsString((Response<String> response) -> {
   String deviceId = response.getResponseData();
   Preferences.set("deviceId", deviceId);
   Log.p("DeviceId: " + deviceId, Log.INFO);
});

The server-side code is quite simple. Staying in the Java world, and assuming we have a Spring Boot server, the code could be:

@GetMapping("/uniqueIdentifier")
@ResponseBody
public String uniqueIdentifier() {
   return UUID.randomUUID().toString().replace("-", "");
}

This solution should be enough. Note that UUIDs must be unique, but they are not designed to be unpredictable. You can see a discussion about this here: https://stackoverflow.com/a/41156/1277576

Alternatively, if your code is to be client-side only, read this Javadoc carefully: https://www.codenameone.com/javadoc/com/codename1/io/Util.html#getUUID--

Util.getUUID() returns a pseudo-random Universally Unique Identifier in its canonical textual representation. This could be enough in most cases.

These are just basic suggestions. Obviously you will need to develop the code so that the deviceId is requested once.

Upvotes: 1

Related Questions