16

I'd like to determine which version of my Android app a user originally purchased from the Google Play Store. I need this info to help support moving from a paid app model to a freemium model.

In iOS7 onwards, you can do this by using [NSBundle appStoreReceiptURL] which returns a URL of the App Store receipt that can be examined.

Is there an equivalent in the Google APIs?

Padavan
  • 1,056
  • 1
  • 11
  • 32
Carlos P
  • 3,928
  • 2
  • 34
  • 50
  • @neilco Why have you removed the iOS tag? I thought it would generate more useful answers, since it's likely that developers who have implemented this in iOS have also had to solve this issue with Android. – Carlos P Nov 04 '13 at 09:23
  • is this what you want http://stackoverflow.com/questions/6593592/get-application-version-programatically-in-android ? – PedroAGSantos Nov 04 '13 at 09:33
  • 1
    @CarlosP I removed the iOS tag because the question is about the Google Play Store and is not relevant to iOS. – neilco Nov 04 '13 at 09:35
  • See my comment above - this is how it's relevant to iOS. EDIT: Fine, but without this tag, I doubt that the question will get enough exposure to relevant experts to get an answer. – Carlos P Nov 04 '13 at 09:51
  • @subspider No, that tells you the current application version. I need to know the ORIGINAL version that was purchased (or the purchase date), regardless of whether the user has since updated. – Carlos P Nov 04 '13 at 11:38
  • @AdrianBrown No, nothing has presented itself yet. – Carlos P Jan 03 '14 at 10:23
  • @CarlosP wondering if you ever made the move to freemium and how you handled previous users. I'd like to do the same, go from paid app to "WhatsApp" model (free for x months, then $x/year). Let me know. – Fraggle Mar 20 '14 at 11:17
  • @Fraggle No, as far as I'm aware nothing has been introduced in Android SDK to handle this, but admittedly it's been a few months now since I looked into it. – Carlos P Mar 20 '14 at 16:18

1 Answers1

15

Getting Time and Date Install


You can get the time and date of the first install of the app by using

long installTime = context.getPackageManager()
                   .getPackageInfo("com.some.package.name", 0)
                   .firstInstallTime;

And the version with

PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
version = pInfo.versionName;

Unfortunately this date will reset whenever the app is uninstalled and reinstalled.

If you go with

PackageManager pm = context.getPackageManager();
ApplicationInfo appInfo = pm.getApplicationInfo("app.package.name", 0);
String appFile = appInfo.sourceDir;
long installed = new File(appFile).lastModified();

you will also find out the date when an application was installed, but the time returned will change every time the package is updated.


Suggested Solution


A solution could be an online database for your application, where you can store each user's ID using AccountPicker, their first-time-install with the methods described above and use them at login. You can also use the App Licensing Service.

http://developer.android.com/reference/android/content/pm/PackageInfo.html#firstInstallTime


Machado
  • 14,105
  • 13
  • 56
  • 97
  • 2
    It's first install time, not purchase date in Google Play Store. The time returned is purely local and not correlated to the play store purchase: reinstalling the app returns a fresh value. – Padavan Jul 21 '15 at 13:49
  • Yes, unfortunately there are only a few workarounds in this matter. I would gently ask to reconsider your downvote since it *does* answer the question. – Machado Jul 21 '15 at 14:07
  • 1
    As the OP, I'm afraid this doesn't answer the question, however helpful a workaround. I need to know the original version that was purchased, so I can enable or disable paid app features. – Carlos P Jul 21 '15 at 15:24
  • @Holmes It do NOT answer the question, cause I need date of actual purchase, not install. In iOS I can get it, and it seems that I can not get it in Android and it makes me mad. – Padavan Jul 22 '15 at 12:58
  • 1
    Up vote for app licensing service which solved my problem, even if this answer does not answer the OPs question. – JohanShogun Jul 22 '15 at 21:36
  • @Padavan, Please consider this. >A solution could be an online database for your application, where you can store each user's ID using AccountPicker, their first-time-install with the methods described above and use them at login. You can also use the App Licensing Service. – Machado Jul 27 '15 at 12:57
  • This solution don't help me to determine which of previous versions of the app user purchase (and this is the subject of my bounty). App Licensing service do not provide such information. – Padavan Jul 27 '15 at 14:38
  • 1
    The approach with firstInstallTime is better. If this date is persisted to a server, regardless or consequent updates/installs this will remain unchanged. – Omar Jul 28 '15 at 09:36
  • @Padavan of course it helps. As you stated before: *The time returned reinstalling the app returns a fresh value.* You can handle it easily on the cloud: you have the first time install to compare and can store new values every time the app is reinstalled. If you are looking for a local solution, I'm afraid Android don't handle it like iOS and requires a little bit extra effort to work. – Machado Jul 28 '15 at 11:32
  • @tardoandre, even assuming the hassle of setting up a server to track this, what can be used as a key to record the install? The advertising ID is not appropriate, the device ID can change. Adding a manifest permission for email is blah - and none of these solutions would help with older already purchased/installed versions anyway... Am I missing something obvious? – mm2001 Apr 26 '16 at 04:31