Skip to content

Instantly share code, notes, and snippets.

@sheerazam
Created April 11, 2016 09:18
Show Gist options
  • Select an option

  • Save sheerazam/b9e93f21b7ab05b71f2d4b6c81d063d0 to your computer and use it in GitHub Desktop.

Select an option

Save sheerazam/b9e93f21b7ab05b71f2d4b6c81d063d0 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
// Add the Google Play services version to your app's manifest
// Edit your application's AndroidManifest.xml file, and add the following declaration within the <application> element. This embeds the version of Google Play services that the app was compiled with.
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- Add the API key to your application -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="Your Api key here"/>
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
//TODO: 1. include compile sdk... ( https://developer.android.com/google/play-services/setup.html )
compile 'com.google.android.gms:play-services-maps:7.3.0'
// Locate the debug.keystore file
Locate your debug keystore file. The file name is debug.keystore, and is created the first time you build your project. By default, it is stored in the same directory as your Android Virtual Device (AVD) files:
OS X and Linux: ~/.android/
// Generate SHA-1 fingerprint
( Command )
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
( Result )
Alias name: androiddebugkey
Creation date: Jan 18, 2014
Entry type: PrivateKeyEntry
Certificate chain length: 1
Certificate[1]:
Owner: CN=Android Debug, O=Android, C=US
Issuer: CN=Android Debug, O=Android, C=US
Serial number: 52d9cb79
Valid from: Sat Jan 18 05:31:53 PKT 2014 until: Mon Jan 11 05:31:53 PKT 2044
Certificate fingerprints:
MD5: ---------------------------------------------------------
SHA1: ---------------------------------------------------------
SHA256: ---------------------------------------------------------------
Signature algorithm name: --------
Version: 3
Get an Android API key
Note: You need an Android API key, not a browser key. You can use the same API key for your Google Places API for Android apps and your Google Maps Android API v2 apps.
Note: Existing keys from a Google Maps Android v1 application, commonly known as MapView, will not work with the v2 API. The Google Maps Android API v2 uses a new system of managing keys.
After following the above steps to activate the API, you end up on the Credentials page in the Google Developers Console, where you can access your project's API keys and other credentials.
If your project doesn't already have a Key for Android applications, create an API key by selecting Create New Key and then selecting Android key.
In the resulting dialog, enter your app's SHA-1 fingerprint, then a semicolon (;) then your app's package name. For example:
XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX;com.example.android.mapexample
The Google Developers Console displays a section titled Key for Android applications followed by a forty-character API key, for example:
AAAAAAAAAA-CCCCCCCCCCCCCCCCCCCCCCCCCCCC
=============================RESULT================================================
Key for Android applications
API key
AIzaSyCX_Be8qLs3Wc83C9FPeYNPl-P6HA1-b2w
Android applications
XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX;com.example.playservices
Activation date
May 2, 2015, 2:17:00 AM
Activated by
[email protected] (you)
//TODO: 2. check if google play services in present
iGooglePlayAvailability = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
if( iGooglePlayAvailability == ConnectionResult.SUCCESS ){
}
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment