How to keep a log of button clicks in Android App - android

I have an App in which I would like to start charging the user after they use a feature 5 times.
The unpaid App allows the user to click a button (to do a pre-determined task), and after that, the user must pay to be allowed to do the same task again.
I need to make sure that the log of button clicks is saved even when the user uninstalls/then re-installs the app - this is the main thing I do not know how to do.
Please kindly help!

first get the device unique ID with:
String id = Secure.getString(
getContext().getContentResolver(),
Secure.ANDROID_ID);
then store this id on your server with number of clicks, so every time the user redownloads your app you can identify the device and check how many times the user clicked the button

Well, if you want to keep this info even if the user reinstall the app, you can't save this info in local storage. You should have a database where you can store a user ID and how many times user has already clicked.
As creating a database and put it online requires some backend work, if you have no backend skills (like me), give it a try to firebase: https://firebase.google.com/
In short words, firebase is a Google solution to provide a backend to your app.
With firebase you'll be able to apply a login system (where you'll have a user ID) and create a dabatase (where you can store infos, like how many times user has used the feature)

Related

When user login in one mobile, the same credientals should not login in another device in android

As I want to implement the login function same as whatsapp . If the user login in one device using (email and password) .The same login should not happen in another device.How to implement this functionality in android
In my application whenever the user login ,the status value will be change as 1 in database, when the same user if login in another device means it will show popup, already exist,If the previous user logout means value changed as 0.
But my doubt suppose if the user as logged in and uninstall the app means again he cant able to login again because the value changed as 1.
For the above situation how to handle.Please someone help me.
I am not sure, but the following idea may work.
As also mentioned here, save every users' phone ID to your DB as well. (I am also adding the code for helping you, but as I mentioned code was written by someone else in the link above)
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
Then, check if the user is trying to log in by using that device which has its ID stored in your DB. If this is the case, directly log in the user. This shows that user deleted the application without logging out.
If the user uninstalled the program in the other device and then enters the application from another device, ask the user to log in again. After user logs in, save the current device's ID in your DB. For security issues, maybe you can store the old logged in device's ID and model and more.
I hope I clearly explained to you the idea. Let me know if that helped or not.
Have a nice week!
You need to maintain session for this. when user logins create and return one sessionId for that user. for all request there after need to pass that sessionId. if same user login from another device overwrite previous sessionId with new one. so that based on that first users request will be invalid. and one user is login on one device only

re loggin using third party( google, FB,Twitter)

This is my first major android application, so sorry if this was asked before, but cant seem to find something relevant to help me.
I am developing an android app, where i have managed to add the google sign in method, using the google's guide. My problem now is how to enable my app, to read the users loggin information after they terminate it and relaunch it. Based on some posts here and other guides (which i cant recall now) what i did was storing a boolean variable in SharedPreferences where it states whether the user is logged in or not. boolean isLoggedIn = sharedPreferences.getBoolean(GoogleLogged, false);
I am loading the SharedPreferences file on the splash screen and make the choice of displaying the login layout or not. other than that I dont save anything else from the login process. I guess that I need to store a token, taken from the google servers, but cant find any relevant solutions.
You want to use the social login using Twitter,Fb and Google.While logging through all of these you will get different user ids as the user id for the same user for google,Fb and twitter will be different ,if you want create a user id for your users and want to use that for further communications.Get the user details from these apis like name,email and respective user id and the method of login which social medium they used for login and respective to that create a web service which will provide the user id for your usercase and store that userid in shared preferences.So in the splash screen you can check that user has logged in or not.

Which way is better efficient to log user's activites(history) in android?

I develop the app which is provide some information to general user. it is not only showing info but also curating and recommending further detail info depending on users history;what the users clicked, searched and acted on the app. (like a google targeting AD).
For this, I have to accumulate user's activites on apps. (which button was clicked, when did they turn on the app and so on...)
For this, I have two ideas.
1. let the app to leave their log text file in local device then append lines in it whenever user act, and upload it when they turn off the app on server DB.[like a batch]
-OR-
2. let the app, update db everytime when user acts something on app by http-post.[like a realtime]
Which way is common tactics(or popular ways) on real field? or can you suggest another way?
thanks for reading.

Identify users without a login

I have an app that sends user location data to the server using webview load html. Since the users are truck drivers I do not expect them to know to login using password and user name every time they use app , so my solution is to for each user to make an app with it's own user name and password embedded into the app using the id field sent to the php page .
`enter code here`url="http://mywebsite.php?id=16"+"&longitude="+longitude+"&latitude="+latitude+"&brzina="+speed+"&vreme="+cal.getTime()+"&datum="+date;
What I am changing in url is the id field sent to php page .
Is there a way for me to automate the creation of Android apps without compiling app every time I have to provide a new app to the driver .Let 's say I am given a list of drivers with their id numbers I put this some were and I get for 15 drivers 15 android apps all with the different id part in url .
Do you need to know the ID before they connect for the first time?
If not, you can store a GUID on the phone, which is created on first time run. as an identifier. And when the GUID comes in to the server for the first time, you log them as a new user with that ID, and from then on, know its them again.
for generating a GUID I recommend the UUID class
and storing/retrieving it, maybe the SharedPreferences Class.
Alternatively, give them a GUID in an ini file, which your app runs off. (which you know the ID before hand.)

How would I go about creating a login

The set-up:
I have an android application that so far can register a user by inserting values into a remote mysql database. I'm now trying to implement the log in.
I was thinking that I can add a "logged in" column to the user table in the database that would store whether or not the user was logged in. Then I would have a trigger that would log the user off after a certain amount of time has been elapsed.
The application's use is to retrieve files based upon if the user has access to a certain file. For this I have an "access" column in the user table table specifying the access a user has to a certain file. I was thinking that when a user clicks an item in a list the application would send their login information and the server would determine if the information was correct then check to see if they had access to the specified file then send back the file if the information is correct.
The problem I'm having though is that checking the registration information takes about 2 seconds alone(due to connecting to the socket and sending a string over the network) and if I try to check both the login and the access id it would take slightly longer.
I feel as if I'm trying to reinvent the wheel but I can't find any viable resources on this matter. Criticisms? Suggestions?
(I wouldn't mind doing a complete redesign I just need to know where to start)
Never connect a client to a db-server. There's no way to intercept hacking attempts, because privileges are very basic (SELECT, UPDATE, etc., they ignore the query):
UPDATE users SET name='%s' WHERE userID=%i // where %i will be defined as the real userID
Above should be a valid query to update the user's account-information, however, a hacker can easily intercept this and change it into:
UPDATE users SET name='%s' WHERE userID=15 // ... or any other variable
Instead, you should create a web based API which will validate each query, or better, support only specific API-commands:
account/update.json?name=%s

Categories

Resources