-2

How can I know if the user has ever used my Android app on this device before?

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
Mr. N.V.Rao
  • 1,082
  • 13
  • 27

4 Answers4

1

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.

  1. From where in the world the application is being used.

  2. Adoption and usage of specific features.

  3. Crashes and exceptions.

  4. In-app purchases and transactions.

https://developers.google.com/analytics/devguides/collection/android/

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
Virag Brahme
  • 2,062
  • 1
  • 20
  • 32
1

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:

How to store User name and password details in strings.xml

How to save app settings?

How to keep information about an app in Android?

Community
  • 1
  • 1
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
1

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 !!

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
0

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

insomniac
  • 11,146
  • 6
  • 44
  • 55