I have an Android game and I'd like to play a sound whenever a players unlocks an achievement,
but I can't seem to find a way to know when the user unlocks the achievement, since most of my achievements are incremental I have no way to code it on the client side, the only way would be some callback called when the Google API shows the achievement box, but I can't find any of those on the documentation... Only thing i found was this: Integrating Google Play services achievements and android notifications
#Override
public void onAchievementUnlocked(final String id)
{
//
}
but I have no idea how to implement that or how to call that method and I had no luck on Google
Use the following code:
Games.Achievements.incrementImmediate(GoogleApiClient apiClient, String id, int numSteps).setResultCallback(new ResultCallback<Achievements.UpdateAchievementResult>() {
#Override
public void onResult(UpdateAchievementResult result) {
if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED) {
// play your sound. achievement was unlocked
}
}
});
This will increment your achievement by the amount of steps you want, and when it is done, it will return some of these codes. If the code is GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED, then it means that increment unlocked the achievement and you can play your sound.
Related
This is my second question here. I am not 100% on the formatting and etiquette yet. I apologize in advance. I have a published app using the BaseGameUtils provided by Google. My achievements unlock properly, and the popups show properly, using incrementImmediate(parameters) with a result. However, the result, which I do receive, always comes back as STATUS_OK, even when the call results in unlocking the achievement. I can't manage to get result.getStatus().getStatusCode() to ever be STATUS_ACHIEVEMENT_UNLOCKED. Can anyone help?
Try to use the code given in this SO question, it will make your achievement increment by the amount of steps you want.
Games.Achievements.incrementImmediate(GoogleApiClient apiClient, String id, int numSteps).setResultCallback(new ResultCallback<Achievements.UpdateAchievementResult>() {
#Override
public void onResult(UpdateAchievementResult result) {
if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED) {
}
}
});
The STATUS_ACHIEVEMENT_UNLOCKED indicates that the incremental achievement was also unlocked when the call was made to increment the achievement.
You can also try to check this related SO question.
I want to get all connected players to game. I can get players that are in google+ circles but I want the player to get all users. I can't find what permission do I need to do this.
I am using this code to get players, but it always returns 0.
PendingResult<LoadPlayersResult> players = Games.Players.loadConnectedPlayers(mGoogleApiClient, false);
players.setResultCallback(new ResultCallback<Players.LoadPlayersResult>()
{
#Override
public void onResult(LoadPlayersResult result)
{
PlayerBuffer buf = result.getPlayers();
Toast.makeText(getApplicationContext(), "players"+buf.getCount(), Toast.LENGTH_SHORT).show();
}
});
this had been pre-announced and then announced a while ago already and method .loadConnectedPlayers() had been deprecated... which merely boils down to, that Google+ had been separated from Play Games and the functionality you are looking for is not available anymore.
in order to get a list of connected players, you would have to use your own API now. Just seen the question is old and had been posted before the announce - nevertheless this appears to be the current status.
need a little help. Im making an android app and integrated Soomla for a simple "No ads" purchase inside my app. Ive a purchase button which should do the actual purchase via google.
What occurs is a popup from google : "Error
authentication needed, You have to login in your google account" .
I think its a small problem, but i dont get what. I am logged in in my google account. Store in Soomla is running ( at least it says so). ive enable test purchase.Im using my phone for the purchase ofc. What i am missing?
public class NoADsButton : MonoBehaviour {
private static bool storeInitialized = false; // prevent store to be initialized twice
void Start () {
if(storeInitialized) return;
SoomlaHighway.Initialize();
StoreEvents.OnSoomlaStoreInitialized += onSoomlaStoreInitialized;
SoomlaStore.Initialize(new SoomlaAssets());
}
public void onSoomlaStoreInitialized() {
storeInitialized = true;
}
public void OnMouseDown(){
StoreInventory.BuyItem("no_ads");
}
And the item ive done as its shown in the soomla example:
public const string NO_ADDS_PRODUCT_ID = "no_ads";
public static VirtualGood NO_ADS_LTVG = new LifetimeVG(
"No Ads", // name
"No More Ads!", // description
"no_ads", // item id
new PurchaseWithMarket(NO_ADDS_PRODUCT_ID, 0.99)); // the way this virtual good is purchased
}
This usually happens when the process of publishing the app for testing wasn't done properly. Try going carefully over Google's instructions, make sure you didn't miss anything. http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-test
I have setup leaderboard using the google game services. I am using the following statement for submitting the statistics after finishing the game.
Games.Leaderboards.submitScore(mHelper.getApiClient(),leaderBoardIdForHits,
totalChanceTaken);
Question :
There may be situation that there will not be the internet services or some failure during the execution of the above submit statement. Also on successful submit of the statistics I need to show a Toast like "Statistics updated". I would like to know if there is any listener method for this.
Define this class:
class myLeaderBoardSubmitScoreCallback implements ResultCallback<SubmitScoreResult> {
#Override
public void onResult(SubmitScoreResult res) {
if (res.getStatus().getStatusCode() == 0) {
// data sent successfully to server.
// display toast.
}
}
}
Then submit your score like this:
Games.Leaderboards.submitScoreImmediate(mHelper.getApiClient(),leaderBoardIdForHits,
totalChanceTaken).setResultCallback(new myLeaderBoardSubmitScoreCallback());
So know when you submit a score, a ResultCallback is set, which is delivered when a leaderboard score has been submitted. And if it has been successfully delivered to the server, display your toast.
I'm writing a game in android using Google Play Games Services. I want to get other players using GamesClient.loadPlayerCenteredScores. The problem has to do with getting the profile image. I use getScoreHolderIconImageUri() and fetch the URI with ImageManager.loadImage. My image loaded listener never gets called and games services stops working like a second after the call, the game continues normally (As if games services was disconnected) and I don't get any error in the log whatsoever except for a warning.
Here is the code:
public void PlayersLoader(){
getMainActivity().getGamesClient().loadPlayerCenteredScores(
new OnLeaderboardScoresLoadedListener(){
#Override
public void onLeaderboardScoresLoaded(int statusCode, LeaderboardBuffer leaderboard, LeaderboardScoreBuffer scores){
if(statusCode==0){
LeaderboardScore score;
String playerId=getMainActivity().getGamesClient().getCurrentPlayer().getPlayerId();
ImageManager imMan=ImageManager.create(getContext());
for(int i=0;i<scores.getCount();i++){
score=scores.get(i);
String name;
if(score.getScoreHolder().getPlayerId().equals(playerId)){
name=getResources().getString(R.string.your_best);
}
else{
name=score.getScoreHolderDisplayName();
}
Uri imuri=score.getScoreHolderIconImageUri();
if(imuri!=null){
imMan.loadImage(new ImageLoaded(name),imuri);
}
}
System.out.println("Finish");
scores.close();
leaderboard.close();
}
}
},getResources().getString(R.string.HighScores),LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_SOCIAL,10);
}
}
class ImageLoaded implements OnImageLoadedListener{
String mName;
public ImageLoaded(String name){
mName=new String(name);
System.out.println(mName);
//This does get printed out (the names of the players)
}
#Override
public void onImageLoaded(Uri uri, Drawable drawable){
System.out.println("imageLoaded"); //This never gets printed out
}
}
This is what I get in the log:
//Your Best
//Player 1 Name
//Player 2 Name
//Finished
//Games Services has stopped working dialog in phone, when I click OK, this warning shows:
//*** Unexpectedly disconnected. Severing remaining connections.
If I remove the ImageManager call and print out the names only, they get printed out correctly and nothing stops working.
I don't know what's happening, I'm desperate.
EDIT
Even if I comment this line:
imMan.loadImage(new ImageLoaded(name),imuri);
the error happens.
It is only when I remove this that it stops happening:
Uri imuri=score.getScoreHolderIconImageUri();
It's so strange! Even if I do not do anything with imuri.
EDIT I posted the issue here. It seems it was a bug of Google Play Services. Sure they will fix it soon!
Sounds like maybe you're running into the same problem described in the public bug tracker. If so, a fix is inbound and things should be working again Real Soon Now[tm].