Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top