Inquiry google game services for current matches - android

I'm implementing turn based game services for a simple game:
https://developers.google.com/games/services/android/turnbasedMultiplayer
I'm using the GameHelper class from basegameutils as recommended.
I want to save some data that isn't relevant (statistics) so I don't want to sent it between players. I'm saving this data locally (sqlite) linking it with TurnBasedMatch.getMatchId().
What I need to know is how to inquiry google game services (I guess via GameHelper) which are the current matches for the signed player, so I can delete old local data.
Thanks.

Looking better at documentation I finally found a solution for that.
If your activity extends from BaseGameActivity you can do the following:
Games.TurnBasedMultiplayer.loadMatchesByStatus(getApiClient(),
TurnBasedMatch.MATCH_TURN_STATUS_COMPLETE,
TurnBasedMatch.MATCH_TURN_STATUS_MY_TURN,
TurnBasedMatch.MATCH_TURN_STATUS_THEIR_TURN)
.setResultCallback(deleteNotPresentMatches);
using your own call back, for example:
private ResultCallback<TurnBasedMultiplayer.LoadMatchesResult> deleteNotPresentMatches = new ResultCallback<TurnBasedMultiplayer.LoadMatchesResult>() {
public void onResult(TurnBasedMultiplayer.LoadMatchesResult r) {
//whatever you want, in my case delete local data for old matches
}
};

Related

android-Specifying authentication between user and admin

I'm writing an android application which will have two types of users.One is admin that s gonna make adding and removing needed stuff and user that is gonna just read only.And I dont know a word about how can i make authentication between them.I need some source and advice.So if I can hear some advice.I really become so happy :)
Thanks in advance.
There would be several approaches to this. One rather quick that gives some flexibility would be to:
1) Create an:
interface ApplicationRights {
boolean writeX()
boolean canSeeButtonY()
}
Then you have a static variable of ApplicationRights interface somewhere accessible from anywhere in the application. (there would be many options for this, this is just a simple way)
To complement this you have two classes:
class AdminRights implements ApplicationRights {
...
}
and
class UserRights implements ApplicationRights {
...
}
Then in that static variable, as soon as you know if it's a User or Admin you
create and put either the UserRights or AdminRights in there. Doing so will allow you to customise this behaviour on a more finegrained level.
And whenever you add a new piece of code that will differ from a User and Admin you can easily add another boolean method in the interface to decide upon the rights. (This would also easily allow you to create more roles than users and admins)
Then to decide and save this to repeat it you can use for example SharedPreferences for knowing which user to create.

How to get programmatically the data usage limit set by user on Android OS configuration?

User can define at Data Usage screen a limite and/or a warning limit for mobile data usage. So how can I get this information by code?
Screen of Data Usage configuration of native OS.
I wanna the limit value and warning value.
I've already tried this but not work and always return NULL to both:
final Long recommendedBytes = DownloadManager.getRecommendedMaxBytesOverMobile( this.context );
final Long maximumBytes = DownloadManager.getMaxBytesOverMobile( this.context );
// recommendedBytes and maximumBytes are NULL
And TrafficStats class just have a data transferred not the limits.
After days searching and research about this problem I couldn't find a answer for that. Bellow I will lift every attempt that I did.
1. Download Manager
With this class you can start download over any network or device
state and it will handle all states e.g. network loss, device reboot,
etc...
There are two methods called getMaxBytesOverMobile and
getRecommendedMaxBytesOverMobile, they was a pretty candidate
to solve this problem at first time. But after code tests and
Download Manager implementantion research I'd found that there is
no way to get thoose values by DownloadManager.
Reason
Thoose methods call Settings.Secure.getLong with they
respective labels
Settings.Secure.DOWNLOAD_MAX_BYTES_OVER_MOBILE and
Settings.Secure.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE in
the turn makes a call to a lazy String map inside inside a
inner class called NameValueCache.
Ok so far but none of inner classes or Settings implementation it
self use DOWNLOAD_MAX_BYTES_OVER_MOBILE or
DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE inside.
I considered the lazy map was populate by a third entity, what
actually happens, so I found the NameValueTable Settings
inner class that handle the new values to lazy map. The
putString is a protected method call by Settings.Secure
and Settings.System inner classes (calls of Secure and
System).
So I could conclude that if the OS implementantion do not put thoose String values I can't get them.
2. TrafficStats
Just a quick look on official reference I could notice that it will
not help me because this class just provide the amount of bytes and
packages that was trafficked since last device boot.
http://developer.android.com/reference/android/net/TrafficStats.html
3. NetworkPolicyManager and NetworkPolicy
As #bina posted here the both classes are hidden and could not
be use by normal apps e.g. that will be published in Google Play.
https://stackoverflow.com/a/24445424/575643
4. ConnectivityManager
In short, you just can get the NetworkInfo that not provide
much information about user preferences (really none!). Just provide
informations about network and e.g. mobile network provider.
http://developer.android.com/reference/android/net/ConnectivityManager.html
After all I assume that no way to get this information nowadays. Please if you read it and found a way post here!
Thanks for all.
PS.: Sorry by english mistakes.
Do you want to get limit value(5GB) and warnning value(2GB) in this example?
If so, you can get limitBytes and warningBytes by the following code, if you can use android.permission.MANAGE_NETWORK_POLICY and android.permission.READ_PHONE_STATE.
However, android.permission.MANAGE_NETWORK_POLICY protectionLevel is signature.
NetworkPolicyManager manager = (NetworkPolicyManager) getSystemService("netpolicy");
NetworkPolicy[] networkPolicies = manager.getNetworkPolicies();
Log.d("NetworkPolicy", "limitBytes is " + networkPolicies[0].limitBytes);
Log.d("NetworkPolicy", "warningBytes is " + networkPolicies[0].warningBytes);
(NetworkPolicyManager and NetworkPolicy classes are hidden)

Description for google play game services Match

I'm implementing a game with turn based multiplayer with google play game services:
https://developers.google.com/games/services/android/turnbasedMultiplayer
My game has some different variations and in order to help users choose easily from the default UI, I would want to add a name for each match.
If it was possible, a player with for example 2 current matches would be able to identify each one easily without opening it.
Thanks.
You could put this information into your Turn data. Like this...
// This is the byte array we will write out to the TBMP API.
public byte[] persist() {
JSONObject retVal = new JSONObject();
try {
retVal.put("data", data);
...
You could then write a custom function to retrieve the match data and you would have to put that information into a custom inbox dialog. I have not done this currently...
This functionality is part of the standard product. Look at the sample from google skeletonTBMP.java and also the skeletonTurn.java (I think it is called). This is where you pass data between turns. It would be fairly easy to populate this into the "data" object which gets updated at each turn, and then display this value on the screen as text. Link here...
https://github.com/playgameservices/android-basic-samples/tree/master/BasicSamples/SkeletonTbmp/src/main/java/com/google/example/tbmpskeleton

Google Play Services - Room - CreatorID Not Unique

Is it just me or is the getCreatorId() method in Room not unique for automatch games?
I have some logic in my game that is based on a unique entity deciding things, such as which player belongs on which team. Each client waits to receive this information from the 'host' (which is the room creator in this case) before launching into and setting up the game.
#Override
public void onRoomConnected(int status, Room room) {
// Game Lobby is full
if (status != GamesClient.STATUS_OK) {
return;
}
this.room = room;
// Assign the players teams
if (room.getParticipantId(activity.gameHelperManager.gameHelper.getGamesClient().getCurrentPlayerId()).equals(room.getCreatorId())) {
// Some logic here
activity.androidManager.sendMessage(Data Sent Here);
activity.game.startGame(GameType.MULTIPLAYER);
}
}
On the other side of things:
#Override
public void onRealTimeMessageReceived(RealTimeMessage message) {
// Get Message from host about game specific properties is here
if (data.contains(Message Tag Here)) {
// Parse information
activity.game.startGame(GameType.MULTIPLAYER);
}
}
However, each client views itself as the host in the onRoomConnected() method during an auto-match type game.
Is there a solution to this or am I missing something fundamental?
Admittedly, our documentation is a bit misleading (I'm requesting a fix right away), but here's the explanation of what went through our heads when we designed this :-D
What automatching really does is connect different rooms created by different people, and making them into virtually one room with everybody in it. So different people in the room may have a different idea of who was the room's creator. So using the room's creator as a way to decide who goes first is generally not a good idea.
Using the participant ID directly isn't a good idea either (because someone with a lexicographically very high participant ID would find themselves going last on every single game they play).
Please see my answer to the following question for more ideas on how to decide who goes first:
How to decide who is the first player when user plays quick game?

How to maintain java collection throughout the Android applications

I am developing an Android application. The content for the application is taken from the webserver using webservice. I am taking the data from webserver and store in mobile db and accessing across the application and its works fine but now problem is while taking more records from mobile db it tooks some time and it application hangs.
Is it possible to maintain the java collection such as hashmap or hashtable to maintain throughout the application until user logout the application and user can add or update the data in collection. If so please guide me.
you should use Application class that ships with Android API .
See this link..
http://www.xoriant.com/blog/mobile-application-development/android-application-class.html
First of all it's better to user db for storing purpose. you should look for optimizing you db querys and the they way you are using it. But anyways you can create a static hashmap or arraylist of your object in your first activity. Then you can use this collection object anywhere you wanted and perform any opration, it will be intect untill and unless you logout of application or any exception occures while working on the collection.
class MylunchedActivity extends Activty{
public static HashMap map = new HashMap();
}
MylunchedActivity should be your first activity. Then by using MylunchedActivity.map, you can work on you map.
i hope this will help.
Regards,
Ravi
use a standalone class or static class to maintain run time static data you need to store.
Created a global singleton in the Application class and was able to access it from the activities I used.
You can pass data around in a Global Singleton if it is going to be used a lot.
public class YourApplication extends Application {
public SomeDataClass data = new SomeDataClass();
// Your JAVA collections...
}
Then call it in any activity by:
YourApplication appState = ((YourApplication)this.getApplication());
appState.data.UseAGetterOrSetterHere(); // Do whatever you need to with the data here.
For more info look at Android Application Class
Here are few possible solutions :
How to store hashmap so that it can be retained it value after a device reboot?
Saving a hash map into Shared Preferences
One is serialize/deserialize and other is using sharedpreference, as your requirement is to save/edit data until user logout.

Categories

Resources