How to set a custom 'user-agent' as header for Android Bitmovin player SDK?

I have gone through the documentation and tried to implement the method PreprocessHttpRequestCallback for altering NetworkConfig to add a custom user agent unfortunately, I couldn’t implement it successfully. I even searched your entire git sample repo for NetworkConfig yet failed to find a sample. Please do share a possible fix, more preferably a sample code would be helpful.

1 Like

Figured it out - below is a sample to add a custom User-Agent in any HTTP request using PreprocessHttpRequestCallback in Java. customValue should be replaced with the preferred User-Agent string.

Note: there was a bug in our old Android player SDK (< 3.17.0) which was the User-Agent overwrite was ignored as described in our release note (Bitmovin Docs - Player Android / AndroidTV Release 3.17.0). So ensure to use version 3.17.0 or later.

NetworkConfig networkConfig = new NetworkConfig();
PreprocessHttpRequestCallback preprocessHttpRequestCallback = new PreprocessHttpRequestCallback() {
    public Future<HttpRequest> preprocessHttpRequest(HttpRequestType httpRequestType, HttpRequest httpRequest) {

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Callable<HttpRequest> callable = () -> {
            HashMap<String, String> headers = new HashMap<>();
            headers.put("User-Agent", "customValue");
            return httpRequest;
        Future<HttpRequest> future = executorService.submit(callable);
        return future;