Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 215
Dino Sunny Avatar asked Sep 05 '25 20:09

Dino Sunny


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.

like image 157
poss Avatar answered Sep 08 '25 09:09

poss