简体   繁体   中英

Android unique id assigning

I have an Android application where users can connect and disconnect to/from a server. I don't want to have any kind of registration in app, but I want server to recognize users that have already been connected to the server. One way to do this might be using Google Play services and Instance id API by sending the id generated by gcm to the server each time client connects. Using Google Play services API I also get a way to implement push notifications quite easily. However, I don't feel that I will need them, and I will also have to implement ios and web clients later. Afaik there is no available Google Play services API for web so this raises the question: what other alternatives might be?

The way I have understood the question is, you want a uniqueId which is unique for every device and you don't want the registration id which we get from GCM. So you have a device Id which is unique for every device and there is a way of getting the device ID

public String uniqueId() {
        final TelephonyManager tm = (TelephonyManager) mContext
                .getSystemService(Context.TELEPHONY_SERVICE);

        final String tmDevice, tmSerial, androidId;
        tmDevice = "" + tm.getDeviceId();
        tmSerial = "" + tm.getSimSerialNumber();
        androidId = ""
                + android.provider.Settings.Secure.getString(
                        mContext.getContentResolver(),
                        android.provider.Settings.Secure.ANDROID_ID);

        UUID deviceUuid = new UUID(androidId.hashCode(),
                ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
        String deviceId = deviceUuid.toString();

        return deviceId;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM