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() {
    @Nullable
    @Override
    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");
            httpRequest.setHeaders(headers);
            return httpRequest;
        };
        Future<HttpRequest> future = executorService.submit(callable);
        return future;
    }
};
networkConfig.setPreprocessHttpRequestCallback(preprocessHttpRequestCallback);
player.getConfig().setNetworkConfig(networkConfig);
2 Likes

Hi, we are using preprocessHttpRequestCallback in android application to send custom Headers with the MPD file to bitmovin, is there a way to check if these headers are being received at Bitmovin’s end?

@anurag.somani You can inspect the network with proxy tools like “Charles Proxy” to check if the request includes the modified headers.

Thank you for your quick response Kishore. Unfortunately, we do not use Charles Proxy, is there any other way to verify the same?

You should also be able to use Android Studio’s network inspector I think. Inspect network traffic with the Network Inspector  |  Android Studio  |  Android Developers