2

I have an application that end-user can input his own google map key and show map. I have proper way to check if key isn't empty, but my problem is to check if map key is valid before showing the map.

I assume that user can input wrong key, like valid google key but for another app.

Is there any way to detect that?

I know that some people check for proper log in logcat but I don't think it's the best way.

Any help will be appreciated.

Thanks

chue x
  • 18,573
  • 7
  • 56
  • 70
Axxxon
  • 703
  • 2
  • 11
  • 27
  • How can you have users input their API keys when it needs to be in AndroidManifest.xml file? – MaciejGórski Mar 29 '14 at 22:49
  • @Axxxon If you are fine with the one of the answers you should "accept" it such that other ppl know that this answer will help them to solve their problem. – Basic Coder Apr 09 '14 at 11:44

2 Answers2

3

If I got you right, you want to validate if the user's key is working. (I dont even think that you can validate other things)

I would create a little ProgressDialog or another UI Element which indicates that you are "validating the API key" and make the user wait until this has been done. Validate the API ke by performing a simple request to the API with this key.

If there is no "simple" API key which can determine if the key is valid you can create a map which is hidden and initialize it with the user's key as described in this answer: MapActivity: set APIKey programmatically Your validation method can than work with the map and call some functions. When an exception is thrown you know that the key is not valid.

Community
  • 1
  • 1
Basic Coder
  • 10,882
  • 6
  • 42
  • 75
  • I'm using SupportMapFragment and in my case i have no exception thrown, just log to logcat, are you sure that in the case you mentioned exception is thrown? – Axxxon Mar 26 '14 at 13:22
  • I said some exception may get thrown. Thus you have to find a method which will throw an exception that indicates that the key is invalid. Finding such a mehod shouldnt be too complicate. – Basic Coder Mar 29 '14 at 17:26
0

how the user get the google map api key for the App you created.For getting the API key we need to provide the keystore file and package name.The keystore file is not available for user so they can't get their own map API key.

And if you are going to provide the API key to the user and allow them to enter then u can validate whether the entered API key is a valid one .For that you can use following logic,

Create a sting variable inside your project and assiangthe API key to it.And when user entered the API key manually check it with the stored one if it is corrct redirect it to map page else close the activity.

I think it will help you

Arun Antoney
  • 4,292
  • 2
  • 20
  • 26