Home » Android » Do Android devices have a static IP address?

Do Android devices have a static IP address?

Posted by: admin May 14, 2020 Leave a comment

Questions:

Do Android devices have a single static IP address that a server could identify them? Im wondering simce that would allow my game to save data without needing a login.

How to&Answers:

This depends entirely on what they are connected to. By default, no. Most Android devices are configured for DHCP for wireless networks and I don’t know of any carriers that assign static IP addresses to mobile devices on their data networks.

Answer:

As other people have already answered, no, mobile devices generally don’t have a static IP address and instead use DHCP to get a dynamic IP address.

However, to answer your base question, you can generate a unique token for the user using the java.util.UUID class. Save this generated token to your app’s SharedPreferences and you can use it to identify your users:

public static String getDeviceUuid(Context context) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

    // Attempt to get an existing device uuid
    String uuid = preferences.getString("device_uuid_key", "");
    if (TextUtils.isEmpty(uuid)) {
        // We don't have a device id, generate one!
        uuid = UUID.randomUUID().toString();

        // Persist the new id to shared preferences
        final Editor editor = preferences.edit();
        editor.putString("device_uuid_key", uuid);
        editor.commit();
    }
    return uuid;
}

Answer:

An Android device can both be connected via WiFi, and 3G, which obviously has different IPs.
The IP address on 3G will also change every time it reconnects.