Android – Setting User Agent or Custom Headers in a Google Volley Request Object

In this tutorial I will show you how to override the getHeaders() function within the Request Object in the Google Volley Networking Library. You might want to add headers in your request to specify request types (for sending JSON), basic login, or manually setting a User Agent.

When you send your request off add a function called getHeaders to the request. Do this by adding the function after the closing bracket of the new Request Object.

Request request = new Request(
    Listener listener,
    ErrorListener errorListener) {
        public Map<String, String> getHeaders(){
        Map<String, String>; headers = new HashMap<String, String>();
        headers.put("User-agent", "YOUR_USER_AGENT");
        return headers;

This is an answer I posted about on StackOverflow about the issue.