You are currently browsing the monthly archive for June 2013.

I believe that you have gone through the first part of this article. i.e,

https://mirnauman.wordpress.com/2013/06/11/our-first-android-google-maps-api-ver-2-0-application-part-1/

In this part we will go through a detail explanation of getting the Api ver 2.0 key one baby step at a time. I ll try not to skip even the smallest step so that fresh developers finds it easy to make it to the finish line successfully. The main sections covered in this article are

  • Signing the application and why its necessary.
  • Retrieving our application’s certificate.
  • Registering our project
  • Our Api project creation.
  • Obtaining the Api key
  • Adding the Api key to our application

Signing the application and why its necessary.

The signing of the application is not something very complicated or suspicious thing. It is used to identify the author of a certain application. Their is no signing authority involved and it is allowed to use self signed certificates for android application. The private key is with the developer of the application. Without signing our application we will not be able to  get the Android Google Maps API Ver 2.0 key. So we have to do it as any cost.  We will skip a lot of boring theory about this signing application and will go through the important part but if the readers are interested in some more details they can always click on the link “Signing Application Details“. Signing can be in two modes. Signing in Debug mode and Signing in Release mode. In this article I ll only go through the Signing in Debug mode.

Signing in Debug mode

To sign our application in Debug mode first we will make sure that we have the “keytool” utility present at our JDK, JRE install location. The keytool is used to create the debug keystore and key automatically. The key is than used to sign the application automatically. The location of keytool on my system is  “C:\Program Files\Java\jre7\bin\keytool.exe”. the debug.keystore is created with predetermined names and passwords. e.g,

  • Keystore name: “debug.keystore”
  • Keystore password: “android”
  • Key alias: “androiddebugkey”
  • Key password: “android”
  • CN: “CN=Android Debug,O=Android,C=US”

Wc can change the location and name of the debug keystore but for now we will leave it as it is. One thing to make note of is that the self signed certificate of debug mode has a validity of 365 days, than it expires. Now to complete the process we have to retrieve our SHA-1 fingerprint and use it to sign our application and get the api key.

What is SHA-1 fingerprint , where and how to find it.

SHA-1 fingerprint is a unique text string generated by SHA-1 hash Algorithm and as it is unique , Google Maps uses it to  identify the application. To find it there are two ways, first use keytool to generate the SHA-1 fingerprint through command prompt. The command is explained in detail in the  link How to get Google Maps API Key but there is a simple way to find out SHA-1 fingerprint but before we get this fingerprint we need to understand that there are two type of certificates through which we can generate the SHA-1 fingerprint.

  1. The Debug Certificate
  2. The Release Certificate

The Debug certificate is created automatically by the SDK tools when the application is built without exporting it as released application. This certificate can only be used for testing and not for publishing the application as released version. The Release certificate is generated by the SDK tools when a release built of the application is done. With this certificate you can the application can be published. For testing and development we will use the Debug certificate. To display the SHA-1 fingerprint on Debug certificate go to Windows menue in Eclipse and click Preferences, than select Android from the list and click Build. We will see the following screen.

Debug keystore and SHA-1 Fingerprint

Debug keystore and SHA-1 Fingerprint

This is the easiest way to display the SHA-1 fingerprint. Note down the SHA-1 fingerprint. Keytool commands from command prompt can also be used to display the same SHA-1 fingerprint. But i guess using Eclipse to display this is alot easier.

Registering our application

We will use our gmapv2 application that we have created in Part # 1 of this series for registration process. Open a browser and navigate to the following link. Google API Console.

You will be prompted for logging In, Log In with your gmail id and password. You will be taken to the following screen.

Google API Console Main Page

Google API Console Main Page

Expand the top Left Dropdown list Where it is written API Project V2 and click Create. A dialog box will appear where will give our new API Project Name, In the above snapshot I have named it API Project V2. Click the Create project button and you will taken the the following screen.

The services tab in the google api console

The services tab in the google api console

Scroll down in the services and find “Google Maps Android API V 2“. The button in front of it will be showing Off. Click it to turn the service on.

Turning the Google Maps Android API v2  service on

Turning the Google Maps Android API v2 service on

When we turn on the service we will be prompted for Terms of Service. Agree and and click Accept button to proceed. Almost at the finish line to get our API key. Get to the Google API Console. In the navigation bar to the left click API Access.

Obtaining The API Key

API Access Page

API Access Page

From the above screen click on “Create new Android key” button. This will bring us to the following screen.

Configure Android Key for our project

Configure Android Key for our project

Copy your SHA-1 that we have previously displayed and noted down. Paste that in the empty text box and than enter a “;” semicolon at the end of the string and write your complete package name so the complete string becomes SHA-1 fingerprint+;+complete package name.

Key Generation

Key Generation

Click create and you will come to the previous screen with the following addition.

Our Google Maps Android API Ver 2.0 Key and Fingerprint with package name

Our Google Maps Android API Ver 2.0 Key and Fingerprint with package name

As you can see on the screen. Our API Key is listed and below that is the SHA-1+;+complete package name that will be some what like this.

A7:95:FC:3D:A8:1E:4B:CD:9D:D3:E2:E0:1B:D4:9C:39:5A:30:74:7F;com.android.gmapv2

The API Key will look like this.

AIzaSyAlm8fZijW4ViYnxfp-zF8-4-WK6LFY0ik
Copy the key and move on.

Adding the key to our gmapv2 application Open the gmapv2 application in Eclipse. Open the AndroidManifest.xml file and write the following code with your own API Key. Just above the application ending tag.

Putting the API Key in AndroidManifest.xml file

Putting the API Key in AndroidManifest.xml file

Now add the necessary permissions to AndroidManifest.xml file.

Setting up permissions in AndroidManifest.xml file for our first Android Google Maps API Ver 2.0 Application

Setting up permissions in AndroidManifest.xml file for our first Android Google Maps API Ver 2.0 Application

Code of the complete AndroidManifest.xml file will look like this.

Complete code of AndroidManifest.xml

Complete code of AndroidManifest.xml

So far we are done with getting the API Key and putting it in our gmapv2 application. In the next part of this series we will go through all the steps of how to deploy or test this application on actual device. How actual device can be connected to Eclipse. What challenges we will face and what are the solutions for that.

Note : Source code for this article

https://docs.google.com/file/d/0B7W5NGdltb1jeXBvRDNqaV9maFk/edit?usp=sharing

Today when i came to office, turned on my computer and logged In. With a cup of tea and going through my unread emails one by one i logged In to my skype as we use that for most of our official meeting with the head office team. The first thing that got my attention was

Wat am I up to

Wat am I up to

I started thinking what am i up to. I was waiting for a meeting to start at 10, but do i really have to tell this to my friends. Than i started thinking what am i really up to and my mind was blank. suddenly i thought lets see what are my friends up to and what can i make up from what they are telling me . Here is a snap shot of what my friends are up to

What are my friends up to

What are my friends up to

Now i write what came to my mind when I was going through each one of their up-to-messages. Will only go for some highlights.

  • Kamran is at Islamabad and he is always at Islamabad, wonder when he will be in some other city, He needs some change and outing.
  • Abdul Rasheed is finally In Battagram as MIS Coordinator, Enjoying my last position. Congratz Rasheed and best of luck for your new position and assignments. I hope u can handle the team their.
  • Ali is some hacking thingi and trying to convince me that i should leave my friends behind as they dont have the qualifying skill set for the gang or at least that wat i can make out of it. 🙂
  • Irum is back to peshawar and was with us in the meeting that i have just attended. I still didnt get from where we started and wat we actually decided in that meeting to do next. will check the minutes of the meeting later.
  • Waqar is always on the run, infact he was the kind of child who never crawled or walked, The day his feet touched the gournd for the first time, he started running like Road Runner of looney toons.
    Wile E. Coyote and Road Runner

    Wile E. Coyote and Road Runner (Photo credit: Wikipedia)

     

  • Shahid Mahmood is still voting for IMRAN KHAN.
    English: Imran Khan, December 2007

    English: Imran Khan, December 2007 (Photo credit: Wikipedia)

    even the elections are history , with half of IK votes gone to trash by Election Fixers.

  • Atif sab has quoted something nice that shows that i fall in the third category, am discussing people.
  • Kyaw is having cofee with his family back home. On his RnR.
    Cofee Time

    Cofee Time (Photo credit: CK | PHOTOGRAPHER)

     

  • Amjad Mahboob qureshi needs our prayers for his upcoming challenges.
  • Asad is enjoying mangoes in hot sun. Bro you need to send some for me.
  • Abdul Qayum is back from US, now that he has taken the decision he has to make it right. And i wonder if i am so much concerned about REEMA stealing his idea, what will be his feelings about that. REEMA started REEMA KA AMERICA
    reema ka america. a copy paste idea

    reema ka america. a copy paste idea

    after he had worked for a few months on ABDUL KA AMERICA.

    abdul ka america. the actual idea

    abdul ka america. the actual idea

    The point is who will watch or read abdul ka america if reema ka america is on air.

  • Achoka luduba is a simple man, he is marketing that.
  • Oh Waqar agian, and this time he is trying to make us believe that afridi’s are not gangsters. Wat about the zillion warships that u have prepared to attack on me bro.
  • Ashfaq ahmed is a proud Pathan and I am the same thing too. But wud like to call my self a proud Pakistani, than a proud Pathan.
  • Lubna status is a blank line, guess her mind is as blank as mine. thinking where to start my day.
  • and the list goes on and on but i guess i have to stop here.

Note:- To all my friends specially those who’s names are listed in the above post. No offense dears. I wrote this just for fun. If some one finds it offensive , Please let me know, I ll remove his part.

Have a nice working day. 🙂

Update 1.0 of this article at the bottom of the page.

Driving agent for this article

There was some stuff that my readers were eagerly waiting for. With the launch of Android Google Maps API Ver 2.0 everything that was in progress with API Ver 1.0 was a mess. The switching had given a hard time to alot of developers as the way even the sample app is successfully executed is way too complicated. I received tons of emails and requests for support specially for getting the Google Maps API Ver 2.0 key and the part where everything seems fine but map is not displayed. A couple of days back i started working on Google Maps API Ver 2.0. I solved the above two issues and alot more but didn’t posted anything because i was in the middle of successfully executing and displaying the Map. The aim was that I’ll start writing once am done with at lease one successful running application and today i have that running app. During this series of articles i ll take my readers from basic setup and configuration to a successful run of their first Android Google Maps  API Ver 2.0 Application.

Before we start I need my readers to keep this in  mind that they need a physical device to develop and test their API Ver 2.0 Application. I am using HTC One X as my physical device

HTC-One-X

HTC-One-X


What we have and what we need

I believe that we have Eclipse installed,  JRE installed and in place as without JRE Eclipse won’t work and Android SDK downloaded and installed, if not Google has made it easy for us with a single download. Download the ADT Bundle for the following link http://developer.android.com/sdk/index.html . The ADT (Android Developer Tools) Includes Eclipse with ADT PlugIn, Android SDK Tools, Android Platform Tools and the latest Android Image for the emulator. You might need to download the JRE and install it to run the IDE. We need the following to get rolling.

  • Physical Device ( I have an HTC One X)
  • Google Play Services
  • Android Support Library
  • An API Ver 2.0 Key
  • OEM USB Drivers (For windows, as am using Windows 7 Professional 64bit)

In part 1 we will only get all these bits and pieces together so that we can make it work in the later sections bit by bit and piece by piece. Lets say we have the Physical Device so we will move to the next thing in the list i.e, Google Play Services. But before we do that we need to start a new project with the name gmapv2 with Android 4.2.2 and Google API Lever 17. (I hope the reader has some background of basic android development.)

Installing Google Play Services

To get the Google Play Services Launch the SDK Manager from within Eclipse. Click Windows>Android SDK Manager. Scroll down the list and mark Google Play Services.  Click the “Install Packages” button and wait till the installation is completed.

Installing Google Play Services

Installing Google Play Services

When the Installation is done, we will add to our project. The easiest way is Right Click on the project and click on Import>Android>Existing Android Code Into Workspace . Browse to the location of the library project.

Importing Google Play Services

Importing Google Play Services

The location of my library project is

F:\Android\adt-bundle-windows-x86_64-20130219\adt-bundle-windows-x86_64-20130219\sdk\extras\google\google_play_services\libproject\google-play-services_lib

We have to take care when doing this. we have to go to the google-play-services_lib inside libproject that is inside the google-play-services folder. When the import is done successful. Now we have to add a reference to our project.

Reference to Google Play Services

Right click on our project and click on Properties. From the list click on Android. Click Add, browse to the google-play-service_lib.

Reference to Google Play Services

Reference to Google Play Services

Now that we are done with Google Play Services, we will come to Google Support Library.

Android Support Library

To add the Google Support Library , right click on the project and click on Android tools. Than click on Add Support Library.

Adding Android Support Library

Adding Android Support Library

Accept the license agreement and install the support library.

Installing Support Library

Installing Support Library

Save your project and we are done with part 1st of this tutorial. In Part 2 we will learn step by step how we will get Google Maps API Ver 2.0 Key. Getting the API key is the most tricky part.

For Android Google Maps Ver 1.0 developers should click on the following link

https://mirnauman.wordpress.com/2012/01/30/using-google-maps-in-android-development-tutorial-part-1/

Note : Source code for this article

https://docs.google.com/file/d/0B7W5NGdltb1jeXBvRDNqaV9maFk/edit?usp=sharing

Update 1.0 (30th JAN 2014):- Before it was not possible to test an Android Google Maps Api Ver 2.0 on Emulator but now its possible. I ll post both the articles soon . Testing the App on physical device and Testing the App on emulator.

Blog Stats

  • 328,022 hits

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 233 other followers

%d bloggers like this: