title: React Native & okhttp on Android - Set User-Agent
body: <p>I'm trying to set the <code>User-Agent</code> with React Native on Android. Did some research and it looks like I should use an <code>okhttp</code> <strong>Interceptor</strong>. An example that I've found explains how this should be done(<a href="https://adiyatmubarak.wordpress.com/2015/12/29/add-user-agent-in-retrofit-2/" rel="noreferrer">Link</a>) but then I am not sure on how to register the Interceptor.</p>
  
  <p>So in order to set the <code>User-Agent</code> I am using this class:</p>
  
  <pre><code>public class CustomInterceptor implements Interceptor {
      @Override public Response intercept(Interceptor.Chain chain) throws IOException {
        Request originalRequest = chain.request();
        Request requestWithUserAgent = originalRequest.newBuilder()
            .removeHeader("User-Agent")
            .header("User-Agent", "Trevor")
            .build();
        return chain.proceed(requestWithUserAgent);
      }
  }
  </code></pre>
  
  <p>Then what's left is to register the above interceptor so where it should be done? Maybe in <code>MainActivity.java</code>?</p>
  
  <pre><code>OkHttpClient okHttp = new OkHttpClient();
  okHttp.interceptors().add(new CustomInterceptor());
  </code></pre>
  
  <p>I am not getting any errors when building the app so I think that the <code>CustomInterceptor</code> should be fine - just need to make the app use it.</p>
  
  <p><strong>UPDATE</strong>:
  I'm currently trying to register the interceptor in <code>MainActivity</code> but it won't pick it up:</p>
  
  <pre><code>public class MainActivity extends ReactActivity {
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      OkHttpClient client = new OkHttpClient();
      client.networkInterceptors().add(new CustomInterceptor());
  
    };
  
  };
  </code></pre>