title: Accessing sharedPreferences inside Retrofit Interceptor
body: <p>Here is a Retrofit Interceptor used to inject automatically a token inside requests. I'm trying to get this token from <code>sharedPreferences</code> but <code>getSharedPreferences</code> is not available there.</p>
  
  <p><strong>How can i retrieve my token from sharedpreferences inside this Interceptor ?</strong></p>
  
  <pre><code>import android.preference.PreferenceManager
  import okhttp3.Interceptor
  import okhttp3.Response
  
  class ServiceInterceptor: Interceptor {
  
      var token : String = "";
  
      override fun intercept(chain: Interceptor.Chain): Response {
          var request = chain.request()
  
          if(request.header("No-Authentication") == null){
  
              if (request.url.toString().contains("/user/signin") === false) {
                  // Add Authorization header only if it's not the user signin request.
  
                  // Get token from shared preferences
                  val sharedPreference = PreferenceManager.getSharedPreferences()
                  token = sharedPreference.getString("token")
  
                  if (!token.isNullOrEmpty()) {
                      val finalToken = "Bearer " + token
                      request = request.newBuilder()
                          .addHeader("Authorization", finalToken)
                          .build()
                  }
  
              }
  
          }
  
          return chain.proceed(request)
      }
  
  }
  </code></pre>