Skip to content Skip to sidebar Skip to footer

Check Value Exists Or Not Using Encryptedsharedpreferences Android

I use the EncryptedSharedPreferences to store value while login...i want to change text in navigation drawer of home activity so when user is loggedin it will show logout else it w

Solution 1:

You are adding the values but not saving them to SharedPreferences. You should be using commit() or apply().

Do this:

val editor = sharedPreferences.edit()
   editor.putString("EmailId", edtEmailId)
   editor.putString("password", edtPassword)
   editor.apply() // Important

I also see that you are calling

val sharedPreference = applicationContext.getSharedPreferences("secret_shared_prefs", Context.MODE_PRIVATE)`

which gives you the normal SharedPreference, I guess. You should be using:

val sharedPreferences = EncryptedSharedPreferences.create(
        "secret_shared_prefs",
        masterKeyAlias,
        baseContext,
        EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
        EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
    ) as EncryptedSharedPreferences

Then check if the email address is empty or not.

if(!sharedPreference.contains("EmailId") 
    nav_connection.title = "Loginn"else 
    nav_connection.title = "Logout"

Post a Comment for "Check Value Exists Or Not Using Encryptedsharedpreferences Android"