Android ID Generate generateId(Object... value)

Here you can find the source of generateId(Object... value)

Description

generate Id

License

Apache License

Declaration

public static long generateId(Object... value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static long generateId(Object... value) {
        //String value to be converted
        try {//from w w w  .  j av a2s .  c om
            StringBuilder builder = new StringBuilder();
            for (Object s : value) {
                builder.append(String.valueOf(s));
            }
            MessageDigest md = MessageDigest.getInstance("sha-1");

            //convert the string value to a byte array and pass it into the hash algorithm
            md.update(builder.toString().getBytes());

            //retrieve a byte array containing the digest
            byte[] hashValBytes = md.digest();

            long hashValLong = 0;

            //instance a long value from the byte array
            for (int i = 0; i < 8; i++) {
                hashValLong |= ((long) (hashValBytes[i]) & 0x0FF) << (8 * i);
            }
            return hashValLong;
        } catch (NoSuchAlgorithmException e) {
            return 0l;
        }
    }
}

Related

  1. generateSyncEventId()
  2. getSequenceId()
  3. generateId(Object... value)
  4. generateRecordingIdentifier()
  5. getAndroidId(Context context)
  6. generateKey()