Wednesday, February 11, 2015

Arch Linux- Android Studio with SHA-1 fingerprint

Cheers !!!!

Using Google API's we can develop Android Applications to integrate either the location based search or maps API and so on.


Creating application for Google Maps, we have to obtain the API key from Google console and include in our code.


In this post I will brief about obtaining the fingerprint which is useful to obtain the Google Map's API Key.


STEP 1::  Launch the Android SDK Manager

               In Android Studio (I used), open the sdk manager console by clicking on the icon







. SDK manager window opens

STEP 2:: Install the Supporting Google API.
             Install Supporting Repository,Google Repository,Google Play Services from the Extras

STEP 3:: Add the Google Play services in  Gradle

              Open build.gradle  configuration file of the application and include the Google Services dependency. such as 
compile 'com.google.android.gms:play-services:4.3.23'

STEP 4:: Create Map Fragment.

              Declare option for the MapFragment by including the tag in fragment xml file:
            <fragement
                    xmlns:map="http://schemas.android.com/apk/res-auto"
               />

During this process if you encounter exception then clean the project by navigating to the project path

      
       c:/home/directory/android_projects/SampleApp> gradlew clean

In few case (including my situation) while performing this command if permission error encountered then provide the editable permission by login as admistrator in terminal and type 
            
            # chmod 777 gradlew


STEP 5:: Obtain the SHA-1 hash fingerprint using keytool

             Firstly determine the path of keytool in .android folder. Usually it is found in home folder such as
/home/.android

navigate to the path and type the command.


$ keytool -list -v -keystore debug.keystore 



Ignore if asked any password asked and just go ahead and press Enter. You will obtain the fingerprints such as


Certificate fingerprints:

MD5:  52:1E:05:92:D7:04:7F:83:D3:86:97:30:7V:3B:62:14
SHA1: 19:8V:6B:F2:2C:93:02:23:2R:8B:5F:C6:F3:63:9E:EB:5E:VB:7A:B3



SHA256: 03:9C:84:EV:6V:4A:C1:88:25:43:7R:57:A8:A1:77:EE:DA:53:CC:E6:F5:



STEP 6:: Paste key in Google Console
              Copy obtained fingerprint and paste in the Google API Console  https://code.google.com/apis/console while creating a new Android key. click save. Voila!!!! Android API key is generated.

STEP 7:: Include in our code
               In order to use the generated API key, go to our manifest file and under the activity tag where we want to use Google Map, add the meta data

       <meta-data 
               android:name="com.google.android.maps.v2.API_KEY"                            android:value="YOUR_API_KEY_HERE"
        />

Boom !!!!!! Run the code and we can see the Map displayed.... !!!!!

Happy Coding !!!!

No comments:

Post a Comment