How to set up Android Emulator WITHOUT Google Play Services - android

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;
}

Related

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

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

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

Is there a Google plus SDK for Amazon devices?

I am integrating google plus into my app and it works fine with the google_play_service library.But since this library doesn't work in amazon devices my app always crash when I share something from the Amazon devices.So it is only possible to avoid sharing in google plus when using Amazon devices or is there a workaround.
Thanks in advance.
Whenever you use the Google Play Services lib, it is important to check whether the device supports the use of Google Play Services. This is done as follows:
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDisplay = (TextView) findViewById(R.id.display);
context = getApplicationContext();
// Check device for Play Services APK.
if (checkPlayServices()) {
// If this check succeeds, proceed with normal processing.
// Otherwise, prompt user to get valid Play Services APK.
...
}
}
// You need to do the Play Services APK check here too.
#Override
protected void onResume() {
super.onResume();
checkPlayServices();
}
/**
* Check the device to make sure it has the Google Play Services APK. If
* it doesn't, display a dialog that allows users to download the APK from
* the Google Play Store or enable it in the device's system settings.
*/
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(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
The above code is usually added to your app's starting activity, and will prevent your application from crashing (throwing an exception) if that device does not support the use of Google Play Services (which is the case with Amazon's Android-based devices). So the answer to your second question, whether we can get access to Google Plus on Amazon devices, is NO.
References:
1. Ensure Devices Have the Google Play services APK.
2. Check for Google Play Services APK.
Yey! soon we cant even use Google Analytics on Amazon android devices! we're already limited in Google Drive support, Chrome cast, Locations API. Developing for "Android" and not only"Google" is becoming harder and harder. Amazon, Google and ebay everyone has its own api for its services.
OR try this.
http://androidcowboy.com/2013/10/add-google-account-kindle-fire-hdx/

how to direct a user to the download page of "Google play services"

My app crashes if a device does not have "Google Play Services" installed in it or if "Google Play Services" in not updated.
I want to direct a user to the download page of "Google play Services" if he does not have Play Services installed in his device.
I have applied an exception but what should I put in the catch block?
I mean how to direct user to the download page of Play Services?
Call GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) to get a status. If the status is not ConnectionResult.SUCCESS, call GooglePlayServicesUtil.isUserRecoverableError(status) -- if that returns true, you should be able to use GooglePlayServicesUtil.getErrorDialog() to display a dialog that will lead the user to download the Play Services Framework.
I think it is too late to answer this, but it could help other people.
Implement this method which check the device to make sure it has the Google Play Services APK, If it doesn't, display a dialog that allows users to download the APK from the Google Play Store or enable it in the device's system settings.
public static boolean checkPlayServices(Activity activity) {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(activity);
if (resultCode != ConnectionResult.SUCCESS) {
Log.e("GooglePlayServices", "Google play services not working.");
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(activity, resultCode, 9000)
.show();
} else {
Log.e("GooglePlayServices", "GCM - This device is not supported.");
}
return false;
}
return true;
}
Hope it helps someone :)

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