Android getDefaultSharedPreferences

Try it this way:

final String eulaKey = "mykey";
Context mContext = getApplicationContext();
mPrefs = mContext.getSharedPreferences("myAppPrefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(eulaKey, true);
editor.commit();

in which case you can specify your own preferences file name (myAppPrefs) and can control access persmission to it. Other operating modes include:

  • MODE_WORLD_READABLE
  • MODE_WORLD_WRITEABLE
  • MODE_MULTI_PROCESS

If you've upgraded to targeting API 30 drop this in your gradle dependencies:

implementation 'androidx.preference:preference-ktx:1.0.0'//For Kotlin Projects

implementation 'androidx.preference:preference:1.1.1'//For Java Projects

After re-synching Gradle change all of your imports from

import android.preference.PreferenceManager

To

import androidx.preference.PreferenceManager