How to allow user to use loadConnectedPlayers - android

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.

Related

Play single track spotify sdk

I am using the Spotify android SDK, and I am trying to get a single song to play, and I would like to potentially play a song after the current one is completed. The issue is that after the song completes Spotify plays a random song afterwards. Is it possible to play the song and not have anything else automatically play after it?
I am simply calling the app remotes player API play function,
mSpotifyAppRemote?.getPlayerApi()?.play(uri)
#Mikee you are doing nothing wrong, Spotify messes around with track replay if you are only using the Free version, if you use Premium it will work correctly. Funny enough if you try playing by an alblum or artist that works with the Free version.
I'm not an expert but from their documentation it looks like you could watch the PlayerState. I'm also not sure when a PlayerState event would trigger but if it's coming back relatively often you could check the track value and see if it's gone to null, or another value and work using that.
Here's a Java example from their website:
// Subscribe to PlayerState
mSpotifyAppRemote.getPlayerApi()
.subscribeToPlayerState()
.setEventCallback(new Subscription.EventCallback<PlayerState>() {
public void onEvent(PlayerState playerState) {
// See what values are in playerState, might be able to determine
// if it's now randomly playing?
final Track track = playerState.track;
if (track != null) {
Log.d("MainActivity", track.name + " by " + track.artist.name);
// If the track is now different, your song has finished, stop it?
}
}
});
I've put a few extra comments in the code above that might yield some results!

Google Play Games achievement result status code is always STATUS_OK

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.

End a multiplayer game on finishMatch

I am developing a turn based multiplayer game in Android using Google Play Game Services.
I have successfully ended the game when the user clicks the Finish Button:
Games.TurnBasedMultiplayer.finishMatch(mGoogleApiClient, mMatch.getMatchId(), mMatch.getData(), creatorResult, opponentResult)
.setResultCallback(new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
#Override
public void onResult(TurnBasedMultiplayer.UpdateMatchResult result) {
processResult(result);
}
});
The current player's game gets updated in the "Completed Games" section.
However the opponent's game is listed as "My Turn"
From the Developing a Turn Based Multiplayer Game in Android page:
"Play Game services sends a notification to all other match participants to inform them that the match is over. These participants see this match under Your Turn category in their respective match list UIs. At this point, your game can call finishMatch() for these participants to save their final game data. Invoking this method also moves the match to the Completed Matches category in the participant’s match list UI."
How do I call finishMatch for the other players?
--Is it through the mGoogleApiClient
--Or is there a way to make the oppononent's match status = MATCH_STATUS_COMPLETE
Can someone please help?
You should make the following call on each of the other players devices:
Games.TurnBasedMultiplayer.finishMatch( mGoogleApiClient, mMatch.getMatchId());
This will cause the following status changes on each players device:
Match status will change from MATCH_STATUS_ACTIVE to
MATCH_STATUS_COMPLETE
Match turn Status will change from
MATCH_TURN_STATUS_MY_TURN to MATCH_TURN_STATUS_COMPLETE.
The participant status of the player will change from STATUS_JOINED to
STATUS_FINISHED.
Note that a players participant status may remain STATUS_JOINED on the other players devices (at least thats what I see in my implementation).

Disable Rematch in Google Play Games

I use Google Play Games Services and everythink working fine (leaderboards, random opponent etc etc)
But when a player call finishMatch(), the status of match.canRematch() is always "true", beyond the result.
If the player has won the battle may not be able to ask for a rematch!
I use this code to send the result:
Games.TurnBasedMultiplayer.finishMatch(mGoogleApiClient,
mMatch.getMatchId(), mMatch.getData(), myscore, creatorscore).setResultCallback(
new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
#Override
public void onResult(
TurnBasedMultiplayer.UpdateMatchResult result) {
processResult(result);
}
});
I would like to disable the possibility of revenge. How can I do?
Ok. This IS an answer.
It is not possible from the API to disallow rematch.
However, I just discovered a workaround that achieves the same effect.
detect whether a match is a rematch by calling getMatchNumber() and getPreviousMatchData(). Cancel/Dismiss the match if the former isn't 1 or the latter isn't null. It ensures a rematch user input will have the same effect as a dismissal.
when a match is completed completely (cancelled, expired, or MATCH_STATUS_COMPLETE && MATCH_TURN_STATUS_COMPLETE), dismiss it right away. It minimizes the chance that the user will even see the "Match complete, rematch" UI. This check can also be checked periodically for matches in the inbox.

Google Play Games Service - Get List of running matches

I'm working on a TurnBased Game with the Google Play Games Service.
Now I would like to list all Games you are involved in the DrawerMenu so you could enter the games very easy and also see what games you are in...
My Question is, how do I get these Games and also how do I get them so I can reenter them on a click?
Hope I could make my Problem clear :)
Thank you!
This is how I did it:
static final int[] statusesToLoad = new int[]{
TurnBasedMatch.MATCH_TURN_STATUS_INVITED,
TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN,
TurnBasedMatch.MATCH_TURN_STATUS_THEIR_TURN,
TurnBasedMatch.MATCH_TURN_STATUS_COMPLETE};
PendingResult<TurnBasedMultiplayer.LoadMatchesResult> loadMathesResult = Games.TurnBasedMultiplayer.loadMatchesByStatus(mGoogleApiClient, statusesToLoad);
loadMathesResult.setResultCallback(new loadMatchesCallback());
And then in the callback you can get data buffers for all the active games you are involved in and all the invitations you received:
private class loadMatchesCallback implements ResultCallback<TurnBasedMultiplayer.LoadMatchesResult>{
#Override
public void onResult(TurnBasedMultiplayer.LoadMatchesResult loadMatchesResult) {
LoadMatchesResponse response = loadMatchesResult.getMatches();
TurnBasedMatchBuffer myTurnMatches = response.getMyTurnMatches();
TurnBasedMatchBuffer theirTurnMatches = response.getTheirTurnMatches();
TurnBasedMatchBuffer completedMatches = response.getCompletedMatches();
InvitationBuffer invitations = response.getInvitations();
}
}
}
You can use these buffers just as you use ArrayList, but you need to keep in mind that google wants you to release() them after you are done. If you won't you're gonna get a notification in your logs about a data leak.
You should use this method:
Games.TurnBasedMultiplayer.getInboxIntent(GoogleApiClient apiClient);
According to the documentation of the method, this method returns an Intent that can be used to start an activity that shows invitations and matches.
Hope this helps. Any other questions feel free to comment and I'll try to answer.
in iOS it is like this:
this one gets all matches where you have been invited and are waiting for you to answer, you can then change the GPGTurnBasedUserMatchStatusInvited to another type with autocomplete.
GPGTurnBasedModel *turnModel = [GPGManager sharedInstance].applicationModel.turnBased;
NSArray *invited = [turnModel matchesForUserMatchStatus:GPGTurnBasedUserMatchStatusInvited];
there is also a function to get ALL the matches but it includes the finished ones, maybe you don't want that.

Categories

Resources