How can I know if the user has ever used my Android app on this device before?
-
You should do some research on Shared Preferences. – rabz100 Dec 10 '13 at 04:24
4 Answers
Check this : The Google Analytics SDK for Android makes it easy for native Android developers to collect user engagement data from their applications. You can do things like : The number of active users are using their applications.
From where in the world the application is being used.
Adoption and usage of specific features.
Crashes and exceptions.
In-app purchases and transactions.
https://developers.google.com/analytics/devguides/collection/android/

- 13,410
- 19
- 69
- 97

- 2,062
- 1
- 20
- 32
You can create these methods to manipulate SharedPreferences:
Keep in mind, there is no way to stop the user from clearing the app data and therefore deleting the SharedPreference.
public boolean hasUsed()
{
SharedPreferences sp = getSharedPreferences("hasUsed",0);
boolean b = sp.getBoolean("hasUsed",false); // default value is false
return b;
}
public void writeUsed(boolean b)
{
SharedPreferences.Editor editor = getSharedPreferences("hasUsed",0).edit();
editor.putBoolean("hasUsed", b).commit();
}
Call them like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// if user hasn't used the app, write to the preference that they have.
if (!hasUsed()) writeUsed(true);
// later in code:
if (hasUsed()) // if the user has used the app
{
// do something
}
}
Links for explanation of code:

- 1
- 1

- 13,410
- 19
- 69
- 97
If you store anything regarding it in your app,user is Owner of his device
. he can clear it anytime.
Kindly store this information on either your server or use some analytics
integration.
But I would prefer to store on server
because in your case,analytics might be overhead
for you as you just want to identify the existing users.
Explaination:
When your app starts, send device's unique id
to your server, so that when user starts the app for next time,it will again send unique id
and at that time your server can perform check in database for existance of recently received unique id
.
In such a manner you can identify that the user has already used your app or not and then you can modify your business logic accordingly.
I hope it will be helpful !!

- 15,348
- 6
- 48
- 57
You can create a shared preference and can update a count value every time the user opens the app, like
SharedPreferences myPrefs = this.getSharedPreferences("myPrefs", MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = myPrefs.edit();
prefsEditor.putString("Count",Integer.valueof(myPrefs.getString("Count", null))+1) );
the code may have errors but the logic is right

- 11,146
- 6
- 44
- 55
-
1The user can simply clear their data for the app and the shared preference will no longer exist. – Michael Yaworski Dec 10 '13 at 04:29