Google map not shown on devices that has android os version 6 - android

I am building application that contains map, and when test it on HTC device that has android os version 6, the map is not showing
can any one help me please?

map is not showing
Reason can be one of the following:
Rebug/Release keystore is wrongly updated in the project you created in developer console SOReference Link for verifying SHA1 Key retrieved
Another issue can be Google playstore service is not the updated one. you can check using the following code
public static boolean isGooglePlayServiceAvailable(Activity context)
{
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(context);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(context, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
}else{
Toast.makeText(context, "This device is not supported. Google Play Services not installed!", Toast.LENGTH_LONG).show();
return false;
}
}else{
return true;
}
return true;
}
Another reason can be of app having wrong gcm_defaultSenderId or wrong values of API KEY in the AndroidManifest
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="A****************************E" />

Check if google play service is installed and also check SHA key is correct or not .Google maps are not device specific.

Have you request the permission at run time?
From Android 6 users grant permissions to apps while the app is running, not when they install the app.
Check here how to request permission:
https://developer.android.com/training/permissions/requesting.html

Related

How to fix apiAvailability.isGooglePlayServicesAvailable misbehaving on emulator

I'm developing an application that uses google maps and I encountered a weird problem when trying to launch my app on emulator - it (obviously) doesn't work and shows an error message "MyApp having trouble with Google Play services. Please try again".
To solve this problem, I decided to check the availability of Google Play Services (as recommended in this guide by Google https://developers.google.com/android/guides/setup). And.. it doesn't work as intended.
So, here's the code I use to check the availability of Google Play Services and the result code for the emulator is always SUCCESS, even though it doesn't have the desired version installed.
private fun checkPlayServices(): Boolean {
val apiAvailability = GoogleApiAvailability.getInstance()
val resultCode = apiAvailability.isGooglePlayServicesAvailable(activity)
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this.activity, resultCode, 9000)
.show()
} else {
Timber.tag("tag").e("This device is not supported.")
}
return false
}
return true
}
In logs I can clearly see the message
W/GooglePlayServicesUtil: Google Play services out of date. Requires 13400000 but found 13280022
And I cannot comprehend why Google says that there are google play services installed on a version without google play service
I expected this function to return some kind of error and show the correct dialog, but it just returns success for the emulator.
Though, if I run it on a version WITHOUT google API, it shows the error correctly about not having google play services completely.
So, my question is - is it a problem with emulator or API and will it misbehave like this on normal phones or this is just an emulator bug (feature)?

Detecting Play Services Installed and Play Services Used in App

What I Have
I have an app that heavily relies on Google Play Services (for Firebase), so I need the user's device to have Play Services installed. More importantly, the Play Services version installed in the device should be equal to or higher than the Play Services I am using in my app.
What I Want
I want to show a message (maybe a dialog or snackbar) in the Splash screen of my app if the user is using an old Play Services version that the version I am targeting in my app.
Like currently, the version of Play Services I am using in my app is 10.0.1. This is the version name obviously.
I know I can do this,
int v = getPackageManager().getPackageInfo("com.google.android.gms", 0 ).versionName;
But I am unable to compare the versions of the Play Services installed in the device and the Play Services I am using? Should I be doing it using the versionCode instead of the versionName? If so, how do I know the versionCode of the Play Services I am using?
Or is there a different (or better) way to do this?
This is method i use .. cheers
public static boolean checkPlayServices(Context context) {
final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
GoogleApiAvailability api = GoogleApiAvailability.getInstance();
int resultCode = api.isGooglePlayServicesAvailable(context);
if (resultCode != ConnectionResult.SUCCESS) {
if (api.isUserResolvableError(resultCode))
api.getErrorDialog(((Activity) context), resultCode, PLAY_SERVICES_RESOLUTION_REQUEST).show();
else {
showToast(context, "This device is not supported.", true);
((Activity) context).finish();
}
return false;
}
return true;
}
Usman's answer is good, additionally you can call GoogleApiAvailability.makeGooglePlayServicesAvailable() in the event of a non-successful result code. Like this:
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
GoogleApiAvailability.getInstance().makeGooglePlayServicesAvailable(this);
}
Further details about result codes, etc. available in docs here: https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability

How to set up Android Emulator WITHOUT Google Play Services

A client is asking me to make a version of my app to run on a device that won't ever have Google Play Services.
Is there any way to tell the Android Emulator to run the app without using GPS?
Then I can test the code to make sure it works on the clients device.
Use a system Image that doesn't contain google APIs.
you will find two types of images as you can see in the photo .
the ones the contain it will be named Google Api system image
,
or you can use genymotion it comes with no google apis installed by default.
Also to be sure you can use this method to check if Google play services are installed
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i("MY TAG GCM", "This device is not supported.");
finish();
}
return false;
}
return true;
}

"this app won\'t work unless you update google play services" error

I am trying to implement the google play services sign-in to my app.
I added libraries (Google-play-services lib, basegameutils lib).I have added the sign in button. The app is not crashing. Everything that I have done seems to be ok.
I signed the app with the keytool and export it, then install it to my phone. I added the SHA1 code to my test app on developers console. And added My app Id to my app.
But when I tap on the sign in button it say with a pop-up "this app won\'t work unless you update google play services". When tap on the "update" it seems the service is up to date.
Is this a problem with my device? Or else What can I try to solve that?
My device is Samsung Galaxy S3.
Update
I added this code :
private boolean checkIfMapsIsOk() {
int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(checkGooglePlayServices, this, 1122).show();
Toast.makeText(getApplicationContext(), "err"+checkGooglePlayServices, Toast.LENGTH_SHORT).show();
return false;
} else {
Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show();
return true;
}
}
and the toast result is "err2". And I looked up for the error numbers from http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html
It says on that site "public static final int SERVICE_VERSION_UPDATE_REQUIRED"
"The installed version of Google Play services is out of date. The calling activity should pass this error code to getErrorDialog(int, Activity, int) to get a localized error dialog that will resolve the error when shown.
Constant Value: 2 (0x00000002)"
So from this I think the reason for error is my device. But my device sees no updates. It is up to date. This is so strange.

Ask for Google Maps Version in my app

I have an app that uses Google Maps. Since, with the new Api in Android, the map wont work if the user don't have the Google Maps app up to date, is there any way that my app can know the version that the user have installed? And... can my app know wich version is the last in Google Play?
the map wont work if the user don't have the Google Maps app up to date, is there any way that my app can know the version that the user have installed?
Your app does not care about the version of Google Maps. Your app cares about having the Play Services Framework installed.
My sample apps, such as this one, use an AbstractMapActivity that wraps up the details of checking for the Play Services Framework, in a call to readyToGo():
protected boolean readyToGo() {
int status=
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status == ConnectionResult.SUCCESS) {
return(true);
}
else if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
ErrorDialogFragment.newInstance(status)
.show(getSupportFragmentManager(),
TAG_ERROR_DIALOG_FRAGMENT);
}
else {
Toast.makeText(this, R.string.no_maps, Toast.LENGTH_LONG).show();
finish();
}
return(false);
}
This will return true if isGooglePlayServicesAvailable() itself returns true. Otherwise, if possible, it will display a dialog (there's an ErrorDialogFragment inner class) that will lead the user to install the Play Services Framework. Or, it will display a Toast for an unrecoverable problem (though production code should use something else, like a crouton).
GooglePlayServicesUtil has its own set of JavaDocs.

Categories

Resources