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/
Related
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
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;
}
According to the documentation GooglePlayServicesUtil.isGooglePlayServicesAvailable returns SERVICE_VERSION_UPDATE_REQUIRED when "The installed version of Google Play services is out of date".
Does this mean that there is a new version of google play services in the play store?
Does this mean that the app needs a newer version than the one that is currently installed in the device?
How is this check done?
this means that the version of google play service you included in your app is higher than the one currently installed on the users device. the user needs to update their google play services in-order for your app to work correctly.
if the result comes back with that error you can simply call this method to alert the user they need to update and it will take them there.
GooglePlayServicesUtil.getErrorDialog(result, this, GOOGLE_PLAY_SERVICE_UPDATE_CODE).show();
result is the result of the isGooglePlayServicesAvailable method
Here are the docs for GooglePlayServicesUtil: http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html.
Here is where they talking about "ensuring" the user has it installed: https://developer.android.com/google/play-services/setup.html#ensure
This is taken from the Official Iosched 2014 source code here:
https://github.com/google/iosched/blob/0a90bf8e6b90e9226f8c15b34eb7b1e4bf6d632e/android/src/main/java/com/google/samples/apps/iosched/util/PlayServicesUtils.java
public class PlayServicesUtils {
public static boolean checkGooglePlaySevices(final Activity activity) {
final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
switch (googlePlayServicesCheck) {
case ConnectionResult.SUCCESS:
return true;
case ConnectionResult.SERVICE_DISABLED:
case ConnectionResult.SERVICE_INVALID:
case ConnectionResult.SERVICE_MISSING:
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
#Override
public void onCancel(DialogInterface dialogInterface) {
activity.finish();
}
});
dialog.show();
}
return false;
}
}
Here is how to use it in an Activity: https://github.com/google/iosched/blob/cf1f30b4c752f275518384a9b71404ee501fc473/android/src/main/java/com/google/samples/apps/iosched/ui/BaseActivity.java
#Override
protected void onResume() {
super.onResume();
// Verifies the proper version of Google Play Services exists on the device.
PlayServicesUtils.checkGooglePlaySevices(this);
}
Does this mean that there is a new version of google play services in the play store?
From the site latest update was on December 2014
Does this mean that the app needs a newer version than the one that is currently installed in the device?
You can check if the device has the higher version ofGoogle Play Service than the one on your app like so:
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable( getApplicationContext() );
if(status == ConnectionResult.SUCCESS) {
//OK
}else if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
Toast.makeText(context,"please udpate your google play service",Toast.LENGTH_SHORT).show
}
Documentation was updated, now it is clear:
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.
Note that all of the current answers reference GooglePlayServicesUtil which is now deprecated. See GooglePlayServicesUtil vs GoogleApiAvailability for details on how to perform the Google Play Services version compatibility check.
I resolved this problem by updating the last version of Youtube library available in : https://developers.google.com/youtube/android/player/downloads
In the gradle :
implementation files('libs/YouTubeAndroidPlayerApi.jar')
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 :)
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.