Search code examples
androidandroid-mapviewosmdroid

Changing User Agent in OSMDroid


Is it possible to change User Agent I send with every tile request in OSMDroid?

I'm currently getting 403 Forbidden error whenever I try to download a tile (as described in another SO question), probably because OSMDroid itself has been banned.


Solution

  • It looks like the only way to specify the User Agent is to modify OSMDroid's MapTileDownloader.loadTile() method in the following way:

    final HttpClient client = new DefaultHttpClient();
    final HttpUriRequest head = new HttpGet(tileURLString);
    head.setHeader("User-Agent", "OSMDroid"); // Add this line
    final HttpResponse response = client.execute(head);
    

    It solves the 403 Forbidden tile download problem.