according to google documentation:
After you have the Maps API key, you need to refer to it from a special attribute - android: apiKey - in the MapView element in the XML layout. If you create a MapView directly from the code, you must pass the Map API key in the MapView constructor .
Therefore, use the mapsView constructor, passing your API key. Please view this link for more information.
EDIT
here is a code snippet for your problem:
@Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); String mapApiKey = <your choice logic here> mMapView = new MapView(this, mapApiKey); setContentView(mMapView); }
source share