Can developer keep track of stats of app? - Android - java

I have made a trivia game app. Is there any way to keep track of, without the user knowing, stats like the following:
How many times a user has played a certain quiz
Overall correct percentage of questions of each quiz and of all quizzes combined
How many times the user ran out of time on a question
etc etc
I would love to be able to keep track of this so I can monitor data constantly to see, for example, if more time is needed on questions because they keep running out of time, etc etc. Right now I don't need a server or any internet interaction to play this game so if that is needed to do what I am asking above, please say that.

You should take a look at Google Analytics for Android. Internet connection will be necesary.

You could do this in a number of ways, all using web services though. It's up to you whether you want to store the statistics on the phone and then send these, or just send each individual statistic on game completion.
You would need a server to act as the web service endpoint which would then be called (using SOAP/REST probably) from the phone either nightly (if you stored the stats on a localdb on the phone) or after each game.
I'd recommend nightly or intervals rather than clogging up the phone owners bandwidth sending stats :)

Related

Handling in-app purchases / consumable products across sessions/devices?

My question is centered around handling in-app purchases for consumables with Google's In-App Billing API. (https://developer.android.com/google/play/billing/api.html#consumetypes)
Their documentation describes consumables as:
Consumable products
In contrast, you can implement consumption for products that can be made available for purchase multiple times. Typically, these products provide certain temporary effects. For example, the user's in-game character might gain life points or gain extra gold coins in their inventory. Dispensing the benefits or effects of the purchased product in your application is called provisioning the managed product. You are responsible for controlling and tracking how managed products are provisioned to the users.
A consumable item is something that could be purchased several times (like in game currency, an in game item or upgrade that is used, etc.), whereas a non-consumable can only be purchased once (no-ads, a skin / character, etc.)
In the documentation on consuming a purchase (https://developer.android.com/training/play-billing-library/purchase-iab-products.html), it also mentions:
How you use the consumption mechanism in your app is up to you. Typically, you would implement consumption for products with temporary benefits that users may want to purchase multiple times, such as in-game currency or replenishable game tokens. You would typically not want to implement consumption for products that are purchased once and provide a permanent effect, such as a premium upgrade.
It's your responsibility to control and track how the in-app product is provisioned to the user. For example, if the user purchased in-game currency, you should update the player's inventory with the amount of currency purchased.
My question is how to keep track of user inventory for consumable products? The documentation and various videos seem to quickly gloss over this, basically saying the app must apply the effects of the consumable when it gets confirmation of a successful purchase. But that isn't really the full picture. What if a user signs out and signs back in with a different account? Or they switch to a new phone, they should have the product on that phone.
You can't really save record of the purchase in SharedPreferences or a persistent cache because it is tied to the phone. If a user signs in on a different phone then they should have the benefits of all the purchases they made.
Take the following example:
A game starts players with 1000 gold. Player buys 500 more gold through an in-app purchase, then spends 200 gold. If player buys a new phone and installs that app on that phone, they should have 1300 gold.
How is this normally accomplished?
Do you need to run a private server that keeps track of purchases/consumption of such things separate from Google?
Thanks!!
I am implementing in-app purchase myself.
Do you need to run a private server that keeps track of purchases/consumption of such things separate from Google?
Yes of course as Google suggests in Security Best Practices
It's highly recommended to validate purchase details on a server that you trust. If you cannot use a server, however, it's still possible to validate these details within your app on a device.
Your second question
What if a user signs out and signs back in with a different account?
Tie the orderId to account or device.
In the first case, you can easily manage the purchase when the user switches the devices(another reason to get a private server).
While in the second case you can allow switching accounts on the same device.
So it's up to you which one to select.
You need to Synchronize local consumption to the server.
This is the flow for Verifying the purchase:
User clicks “BUY” button.
Makes payment with google.
App receives “receipt” from google and store it locally
Send this “RECEIPT” to the Server.
The Server sends the “purchaseToken” to Google Play Developer API for validation
The Google Play Developer API sends response with status code.
Store the RECEIPT in the server database (If we you to keep history of purchases by users).
This is the flow for Consuming the product:
The user opens the app.
App assigns values to the Resources by reading from local storage.
App tries to synchronize with the Server.(checks last updated timestamp)
Different scenarios:
Synchronization Successful: Assigns Resource values from the server. Set newly retrieved values in the local storage.
Synchronization Failed: Keep Resource values and try again.
User consumes the Resource.
App updates local values in Resource and sync with the server.(checks last updated timestamp)
I used Following articles:
Tutorial: How to Implement In-app Billing in Android LINK
Article on implementing InApp purchase LINK.
How to verify purchase for android app in server side (google play in app billing v3) LINK.
Another SO answer LINK.
Another SO answer LINK.
Code Project Sample LINK.

Getting user behavior on the Android Phone (App History, Browse History etc)

Is it possible to get the user behavior on the phone (for example Alpesh has an Android phone and he uses multiple apps, browser YouTube etc). Whatever he is doing on the phone I want to get all those things from behind (which apps he has installed, which app he opens and what he search on the phone, All these data I want to get programmatically so what all can be get in android).
For now I am aware that installed apps list can be get easily but I want to get usage history and what he do all on mobile.
This is not a code solution, but an answer to your question, so you can get start some where.
In my opinion your question title are asking about two things.
(part 1) Getting User Behavior on the Android Phone (part 2)(App History, Browse
History etc)
1- First part Getting User Behavior on the Android Phone:
There is a concept called context awareness. Short described; it is about gathering different information from the phone, like light sensor, motion sensor, sound, location or even user behavior etc. and depending on your app requirement and the gathered information:
You could send these information over cloud data store for statically usage
You could make your phone doing (behavior) different things depending on location, motion or what ever.
etc.
For context awareness it is an open area for pervasive computing research. And it is not just few lines of code to write, it is typically a complete solution depending on requirement. Example I have built a context awareness application to gather noise collected by phones from different locations for research purpose inspired from this framework, but I am pretty sure you can find other frameworks or even build your own, as I did in my case.
The mentioned framework has some examples.
2- The second part is about App History, Browse History etc.:
This is possible, but you still need to build a peace of software (App) to collect all these information (logs) from the phone. Hereafter you can make phone act on different conditions and/or again send it over a RESTful API over cloud service data store, there is no limit for it.
The problem is, there is no thing out of the box for your requirement. Even if you find frameworks you still need to research it and further work on it.
You can find different examples for your requirement, like to collect browser history, you can find SO question here:
Get browser history and search result in android
Or get list of installed application:
How to get a list of installed android applications and pick one to run
My point here is you need to solve small goals at a time and put your knowledge together at the end.
Both 1 and 2 can also be related to each other, depending on your achievement.
Conclusion
Make a goal to your project.
Define the main requirements and tasks of your project.
Research your options (Technology, Cost, Target Audience, What data I can or I should not collect, what is possible to collect, what is the limits, Privacy issues etc.).
Split your project in small assets and try to solve small problems/goals.
Finally you would be able to put the puzzles together and build your final application
but i want to get usage history and what he do all on mobile
This is not possible and shouldn't ever be possible. Each app is sandboxed by Android so apps cannot inspect what other apps are doing. Think about it, you wouldn't want apps to be able to intercept private information such as banking details.
Every app is isolated from the other ones. Unless you develop a system signed app, you will not be able to gather all that data.
What you could do is to develop your own Android Rom where you then develop your data collection the exact way you want. Then you need to distribute your rom, which is another story...

libGDX unlockables management and gdx-pay\Native Android\IOS payments

I want to implement unlockable characters that can be purchased and I have a few questions about the best way to implement this in my game.
Currently I manage unlockables by storing them as preferences. However I'm now in the process of making them purchasable.
Is gdx-pay the best way to do this or create a native Android\iOS
implementation?
Once a method of purchasing characters has been implemented and the
user purchases one, what happens when the user uninstals my game?
i.e. should I reverify purchases on startup? This will require an
network connection, if the user doesn't have one it doesn't restore?
Should I be using preferences to store unlocked characters etc or
another method? My reason behind this method was to avoid having
ship a database with it and having to create separate sqLite
implementations for each platform.
Any advice would be much appreciated.
Point 1. Yes, for now if you want to go cross platform then gdx-pay is your choice. Recently they've also added support for IOS 9 which is great. You will be able to deploy on both Android and IOS with minimal change of code.
Point 2. You should always call requestPurchaseRestore in your splashScreen or somewhere on startUp to restore any purchases. This will ensure that even if the user uninstalls the game and installs it on another mobile device they will still have the purchases they've made. Of course, network connection is vital. If you don't have network access and you call requestPurchaseRestore you will get an error. That's why you should have a method to check if the user has access to the internet (wi-fi or mobile enabled) and only then call requestPurchaseRestore. If the user doesn't have internet they won't be able to restore Purchases. I don't see a problem with that. You can put a label somewhere that you need internet to restore purchases.
Point 3. Yes, having a local preferences file is a good idea. This is what I do myself. If an item is purchased you simply store it in the file. You may well use a db too but it's too much hassle for this kind of job.

how to use java sockets to connect to an online server

I have spent some time learning Java and in doing so have built myself a rather complex game. My game is a desktop ran swing app which after play results in a score value that gets entered onto a leaderboard. The game is pretty much complete, except a few security mechanisms.
At first I never intended to have my game connected to the net as the phrase 'networking' has always put me off. Now that my game has slowly developed, it has actually turned out far better than I had imagined which has kinda twisted my arm into wanting to learn how to network.
After lots of research into the subject, I decided to have a look into sockets and build myself a simple client/socket server. Both programs connected on my local machine which has bought me here.
I already know that allowing the client to send the score to the server is always vulnerable to cheats, but originally this game was never intended for online score posting. Instead I have decided to make my game code so damn unreadable and messy that it may just be easier to cheat/crack someone elses program. (wishful thinking).
This game is only a learning curve, so abuse of the score system in my eyes will only serve to teach.
My questions may seem silly, but its only trying to get a fuller understanding.
I'm wanting to use a socket to send a number, lets say 2371 from my desktop game to a java server that is hosted on a random webserver. I then want the java server to find the position of this players score (2371) and then print the score on a website leaderboard.
Is it really as simple as adjusting the code URL and then uploading the socketServer code to webhosting space?
If it is, what am I uploading..... a .java file, or any other?
I have also read many times in my research that alot of webhosts dont allow the uploading of java files with open ports. Is this correct?
Many thanks guys, this is a subject that I have always steered clear of, so all and any advice would be appreciated.
What you need is a computer on the internet that can run a process (your Java server application), that your Java client applications can connect to. So you would upload the file(s) (maybe it's a jar, or some class files), and tell the server through whatever interface you have to run the process. This server application can then hold everyone's scores and save them to disk and whatever else you need.
I have also read many times in my research that alot of webhosts dont allow the uploading of java files with open ports. Is this correct?
This is correct. You'll need to rent a server (if you don't have one yourself that you can put on your own internet connection), a simple web hosting companies will not allow you to host your own running process.
Instead I have decided to make my game code so damn unreadable and messy that it may just be easier to cheat/crack someone elses program. (wishful thinking).
I'm not sure if this a joke but there's source code obfuscators out there like ProGuard which do exactly this.
If you really want to protect against people simply writing scores out to the server with their own modified client then you'll have to have some of the logic of the game be handled by the server process itself. Of course someone could still go further and create a bot or whatever else they need to cheat and get their bogus score listed.

How to manage online users in IM applications such as GTalk, Skype etc

Do they keep an online user list in a database and update it with every login and logout event, and run queries for online friends?
What about scalability?
Are there better solutions?
If you try to either store presence in a traditional database, or poll for changes to anything, you're going to have a tough time scaling your presence system. Start with one of the open source XMPP servers, pull it apart, and see how it works. Each one of them scales differently, but at least you'll understand more about where you need to start.

Categories

Resources