Alternative way removes security warning when using ANDROID_ID and how to get the device id?

Viewed 2726

public static String getDeviceID(Context mContext) {

    String deviceId = Settings.Secure.getString(mContext.getContentResolver(),
            Settings.Secure.ANDROID_ID);
    return deviceId;
}

This shows a security warning,

"Using 'getString' to get device identifiers is not recommended "

How to resolve this warning?

1 Answers

You can't really "resolve" this warning.

Lint is trying to move you from android ID to advertising id if possible, because for most use cases it's better for user. If you want to disable the warning @SuppressLint("HardwareIds") takes care of that.

Related