Showing posts with label Google Maps. Show all posts
Showing posts with label Google Maps. Show all posts

Monday, October 19, 2015

Google Maps No Longer Requires STORAGE Permission!

For a long time, Google Maps Android SDK requires us to have WRITE_EXTERNAL_STORAGE permission. It was not the case when they first released the SDK.

I didn’t want to have that storage permission first, because In app permission “The permission description says that the application can access files on the devices such as images, videos or audio”. 
I had lots of 1, 2, 3 stars in app ratings because of this. Users say that “Why do you request access for my photos and videos?”. They are right! They are always right. I don’t want to access your photos and I won’t. I am forced to have that permission.
Android Marshmallow brought us run-time permissions. They are great! Users do not see permissions when they install or update the app. Users have more control over the app’s functionality.
for example, a user could choose to give a camera app access to the camera but not to the device location.
But imagine you have an app with Google Maps integration, and imagine you have to request WRITE_EXTERNAL_STORAGE on runtime to show the map. How would you explain that to users? Runtime permissions that are not obvious and require explanation are the worse. This is one of them.
Fortunately, they fixed the issue and removed storage permission. But not for all, just for Android Marshmallow.
If you use Google Maps and you want to target Android Marshmallow, this is what you need to do:
  • First you need to use Google Play Services 8.1.0
  • Second, you need to add maxSdkVersion property in your permissions as shown below:



They also say in the documentation that they will remove it completely in the next release.
From the next release of the Google Play services SDK, the requirement for the WRITE_EXTERNAL_STORAGE permission will be completely dropped from the Google Maps Android API.

Note: Please do the described changes in your application if you have Google Maps and want to target Android M!


Thanks for reading :) 
Whether this post is helpful?

Have something to add to this post? If you have any other quick thoughts/hints that you think people will find useful? Share it in the comments. feedback are welcome...

Thursday, November 7, 2013

Google Maps Android API v2 : mapFragment.getMap() returns null


If mapFragment.getMap() returns null then map is not verified from the GooglePlayServices.

Google Play Services
Give apps more features to attract users on a wider range of devices. With Google Play services, our app can take advantage of the latest, Google-powered features such as Maps, Google+, and more, with automatic platform updates distributed as an APK through the Google Play store.

This type of exception occurs when there are no proper GooglePlayServices updates.
We can check using GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) method, Which returns status code indicating whether there was an error or not.

public static int isGooglePlayServicesAvailable (Context context)
Verifies that Google Play services is installed and enabled on this device, and that the version installed on this device is no older than the one required by this client.
Returns
status code indicating whether there was an error. Can be one of following in ConnectionResult: SUCCESS, SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID, DATE_INVALID.

Map the output of GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) return value with ConnectionResult class Constants. We can find the response of GooglePlayServices.

Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment = (SupportMapFragment) fragment;
map = mapFragment.getMap();

if (map != null) {
// The Map is verified. It is now safe to manipulate the map.
}else {
int checkGooglePlayServices = GooglePlayServicesUtil
              .isGooglePlayServicesAvailable(this);
       if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
              // google play services is missing!!!!
              /*
               * Returns status code indicating whether there was an error.
               * Can be one of following in ConnectionResult: SUCCESS,
               * SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED,
               * SERVICE_DISABLED, SERVICE_INVALID.
               */
              GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices,
                     this, REQUEST_CODE_RECOVER_PLAY_SERVICES).show();
       }
}

Below are the error codes used by GooglePlayServicesClient.OnConnectionFailedListener

Constants
int
The device date is likely set incorrectly.
int
The application is misconfigured.
int
The Drive API requires external storage (such as an SD card), but no external storage is mounted.
int
An internal error occurred.
int
The client attempted to connect to the service with an invalid account name specified.
int
The application is not licensed to the user.
int
A network error occurred.
int
Completing the connection requires some form of resolution.
int
The installed version of Google Play services has been disabled on this device.
int
The version of the Google Play services installed on this device is not authentic.
int
Google Play services is missing on this device.
int
The installed version of Google Play services is out of date.
int
The client attempted to connect to the service but the user is not signed in.
int
The connection was successful.


Note: Do Google Play Services Verification when we are using services of Google.

Origin References:

Tuesday, August 20, 2013

Android: Solution for Google Maps API v2 is not working due to authentication issue


If your facing below exception when you’re trying to hit Google map.

I/Google Maps Android API(2470): Failed to contact Google servers. Another attempt will be made when connectivity is established.

E/Google Maps Android API(2470): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

Check whether you have followed Google maps documentation,
If you feel, everything is achieved but still map is not appearing and you're getting above exception then we should check the below mentioned solution.

Solution / Checks:

When you’re facing authentication issue with your application then check two things.
1.     Whether you’re behind the proxy.
2.     Whether you’re debug.keystore file is signed or not.
If you’re using default android debug.keystore then it is not signed.