I'm trying to use Google cloud messaging for an android app (Target name: Google APIs, platform: 4.3, API level: 18. I implemented my GCM client by following the isntructions here: http://developer.android.com/google/gcm/client.html, and setup play services by following the steps here:
http://developer.android.com/google/play-services/setup.html#Setup, but still get the above error Most of the solutions I've found on stack overflow redirect to the above two links, or suggest that we change the dependencies {} in the gradle settings, but I'm using eclipse and don't have gradle setup.
Update: Sorry yes I'm using the emulator and not a device
Any ideas?Thanks!
If you need to provide an option for the user to update the google services you can do this:
switch (isGooglePlayServicesAvailable(this)) {
case 2: //out date
try {
GooglePlayServicesUtil.getErrorDialog(2, this, 0).show();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
This will prompt an update dialog for the user to update play services
The final solution was creating a new emulator under Android 4.4.2, with the build target of the project set to Google APIs (x86 System Image). Thanks to Pedro Oliveira!
Related
recently I ported my old Android game developed in Eclipse from 2011-2016, to Android Studio because I was forced to a much higher MinSdk by Google. To the following according to build.gradle:
compileSdk 30
minSdk 26
targetSdk 31
Everything worked fine after the porting, but I am not able to get the GooglePlayServices (Leaderboards, Achievements) working again.
I am able to trigger that the user signs in with it GooglePlay account. This works and I get the account and can log its name. That is working.
mGoogleSignedInAccount = completedTask.getResult(ApiException.class);
Log.e(TAG, "account: " + mGoogleSignedInAccount.getDisplayName());
But when I try open the leaderboard, so that the user can see their highscore compared to other players
LeaderboardsClient lbc = Games.getLeaderboardsClient(v.getContext(),
ApplSettings.getInstance()._mainActivity).mGoogleSignedInAccount);
Task<Intent> lbt = lbc.getAllLeaderboardsIntent();
lbt.addOnSuccessListener(new OnSuccessListener<Intent>() {
public void onSuccess(Intent intent) {
Log.d(TAG," ..onSuccess");
((Activity) (v.getContext())).startActivityForResult( intent, 9004 );
}
});
lbt.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Log.d(TAG,".. onFailure: "+e.toString());
}
});
I get the following error:
.. onFailure: com.google.android.gms.common.api.ApiException:
17: API: Games.API is not available on this device.
Connection failed with: ConnectionResult{statusCode=DEVELOPER_ERROR, resolution=null, message=null}
I really don't understand this error. What does it mean? It is independent of the phones I use (OnePlus6T, Samsung Galaxy S9). And of course other game apps on those phones, including my other older games app, can show Leaderboards!
What is also strange, is the following message in the GooglePlayConsole of my app in Play-GamesSevice->Configuration.
It says the 5 tasks have to be done to enable the Play-GameServices, and its states that 4 have been done, and 1 task is remaing:
Play-GameService enabling:
Create a Play GamesService project -> done
Create OAuth ConfirmationScreen in the Google Cloud Platform -> done
Create Credentials -> done
Add the SDK for Google Play-GamesServices to your production APK -> OPEN !!!
Publish Project -> done
What does point 4 mean? How to add an SDK to my games app?
Is it not enough to mention those play-service 'libraries' in the build.gradle of my app?
buildscript {
repositories {
google()
mavenCentral()
}
}
dependencies {
. . .
implementation 'com.google.android.gms:play-services-games:23.1.0'
implementation 'com.google.android.gms:play-services-measurement-api:20.0.0'
implementation 'com.google.android.gms:play-services-auth:20.4.1'
}
So I am not sure if this task (number 4) mentioned by Google as outstanding, is related to the error "Games.API is not available on this device", but it would make sense.
But still I don't understand "not available on this device"? Does not the app is build with libraries that communicate with the Google services in the cloud? What shall be missing on the device? All games app (my other very old game, and also very new apps) can without problem show leaderboards on my devices I use for testing.
I am creating an app with the use of Android Enterprise.
For that, I added dependencies in the build.gradle file.
implementation 'com.google.apis:google-api-services-androidmanagement:v1-rev84-1.25.0'
I am trying to disable uninstalling application using below code from here
try{
Policy policy = new Policy();
policy.setUninstallAppsDisabled(true);
} catch (Exception e) {
e.printStackTrace();
}
But above code is not working. No any Exception or Warning arise
What I am missing? Not able to found proper documentation that how to use Enterprise Management API.
Using the client library of the Android Management API from an Android app is not enough the manage the device the app is running on. You need to first set up the device as managed. For that you can follow the instructions in the quickstart guide.
I need to detect my application is installed from google play or other market, how could I get this information?
The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.
EDIT: Note #mttmllns' answer below regarding the Amazon app store.
And FYI apparently the latest version of the Amazon store finally sets PackageManager.getInstallerPackageName() to "com.amazon.venezia" as well to contrast with Google Play's "com.android.vending".
I use this code to check, if a build was downloaded from a store or sideloaded:
public static boolean isStoreVersion(Context context) {
boolean result = false;
try {
String installer = context.getPackageManager()
.getInstallerPackageName(context.getPackageName());
result = !TextUtils.isEmpty(installer);
} catch (Throwable e) {
}
return result;
}
Kotlin:
fun isStoreVersion(context: Context) =
try {
context.packageManager
.getInstallerPackageName(context.packageName)
.isNotEmpty()
} catch (e: Throwable) {
false
}
Update:
The feature is now obsolete on versions Android 10 or higher.
Installs with missing splits are now blocked on devices which have Play Protect active or run on Android 10.
Follow this on version lower than Android 10
If you are looking at identifying & restricting the side-loaded app. Google has come up with the solution to identify the issue.
You can follow as below
Project's build.gradle:
buildscript {
dependencies {
classpath 'com.android.tools.build:bundletool:0.9.0'
}
}
App module's build.gradle:
implementation 'com.google.android.play:core:1.6.1'
Class that extends Application:
public void onCreate() {
if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
// Skip app initialization.
return;
}
super.onCreate();
.....
}
With this integration, google will automatically identifies if there are any missing split apks and shows a popup saying "Installation failed" and it also redirects to Play store download screen where user can properly install the app via the Google Play store.
Check this link for more info.
Hope this helps.
I have a paid app on the Google Play Store and have been using the LVL library for the past two years. In the past, I tested my app on multiple devices including Android V2.3.5 (Gingerbread), V4.4 (KitKat) and V5.1 (Lollipop), everything worked fine connecting to the google license server.
Recently, I retested on all my Android devices and found the license verification library runs perfectly on Android V4.4 and V5.1 but I can't make a successful connection from the V2.3.5 (Gingerbread) device (Motorola Electrify).
I get a responseCode = 0x101 (ERROR_CONTACTING_SERVER) in the verify() callback on the older v2.3.5 device - appears to time out connecting. I tried several accounts and both fail in the same way on the older Gingerbread platforms.
I also tested earlier APK files that used to work and they fail now also.
Did support for older Android OS versions get dropped over the past year?
Is there something I need to change to support the older devices?
Thanks in advance,
Phil
SDK LVL code
class LicenseValidator {
...
public void verify(PublicKey publicKey, int responseCode, String signedData, String signature) {
String userId = null;
// Skip signature check for unsuccessful requests
ResponseData data = null;
if (responseCode == LICENSED || responseCode == NOT_LICENSED ||
responseCode == LICENSED_OLD_KEY) {
// Verify signature.
...
switch (responseCode) {
case LICENSED:
case LICENSED_OLD_KEY:
int limiterResponse = mDeviceLimiter.isDeviceAllowed(userId);
handleResponse(limiterResponse, data);
break;
case NOT_LICENSED:
handleResponse(Policy.NOT_LICENSED, data);
break;
case ERROR_CONTACTING_SERVER:
Log.w(TAG, "Error contacting licensing server.");
handleResponse(Policy.RETRY, data);
break;
case ERROR_SERVER_FAILURE:
Log.w(TAG, "An error has occurred on the licensing server.");
handleResponse(Policy.RETRY, data);
break;
Okay, I figured it out tonight. Post Google Play Services 10.0.1, support for Gingerbread V2.3 is depreciated.
https://9to5google.com/2016/11/21/google-play-services-gingerbread-support-end/
https://developers.google.com/android/guides/releases
"Highlights from the Google Play services 10.0 release.
Google Play services updated to 10.0.1
This release fixes a missing minSdkVersion value in play-services-location.aar that caused unintended WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE, and READ_PHONE_STATE permissions to be merged into app manifests.
Android version 2.3.x (Gingerbread) Deprecation
Google Play services 10.0.x is the final release that includes full support for Android version 2.3.x (Gingerbread). Apps developed using future SDK releases after 10.0.x will not be able to connect to Google Play services on Android Gingerbread devices. To learn more about your options, including building multiple APKs to extend your app's support for Android Gingerbread, see the Android Developers Blog."
Phil
I need to detect my application is installed from google play or other market, how could I get this information?
The PackageManager class supplies the getInstallerPackageName method that will tell you the package name of whatever installed the package you specify. Side-loaded apps will not contain a value.
EDIT: Note #mttmllns' answer below regarding the Amazon app store.
And FYI apparently the latest version of the Amazon store finally sets PackageManager.getInstallerPackageName() to "com.amazon.venezia" as well to contrast with Google Play's "com.android.vending".
I use this code to check, if a build was downloaded from a store or sideloaded:
public static boolean isStoreVersion(Context context) {
boolean result = false;
try {
String installer = context.getPackageManager()
.getInstallerPackageName(context.getPackageName());
result = !TextUtils.isEmpty(installer);
} catch (Throwable e) {
}
return result;
}
Kotlin:
fun isStoreVersion(context: Context) =
try {
context.packageManager
.getInstallerPackageName(context.packageName)
.isNotEmpty()
} catch (e: Throwable) {
false
}
Update:
The feature is now obsolete on versions Android 10 or higher.
Installs with missing splits are now blocked on devices which have Play Protect active or run on Android 10.
Follow this on version lower than Android 10
If you are looking at identifying & restricting the side-loaded app. Google has come up with the solution to identify the issue.
You can follow as below
Project's build.gradle:
buildscript {
dependencies {
classpath 'com.android.tools.build:bundletool:0.9.0'
}
}
App module's build.gradle:
implementation 'com.google.android.play:core:1.6.1'
Class that extends Application:
public void onCreate() {
if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
// Skip app initialization.
return;
}
super.onCreate();
.....
}
With this integration, google will automatically identifies if there are any missing split apks and shows a popup saying "Installation failed" and it also redirects to Play store download screen where user can properly install the app via the Google Play store.
Check this link for more info.
Hope this helps.