确定日期(或版本)的应用程序从谷歌Play商店购买 - iOS设备appStoreReceiptURL等效应用程序、商店、日期、版本

2023-09-07 14:03:46 作者:没公主命就别犯公主病

我想确定我的Andr​​oid版本应用程式最初是从谷歌购买的用户Play商店。我需要这个信息,以帮助支持付费应用模式转向免费增值模式。

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.

在iOS7起,您可以通过使用做到这一点 [一个NSBundle appStoreReceiptURL] 返回App Store的收据,可以检查的URL。

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

有没有在谷歌API的等效?

Is there an equivalent in the Google APIs?

推荐答案

您可以通过使用获得的时间和第一次安装应用程序的日期

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;

以及版本与

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

不幸的是,每当应用程序被卸载并重新安装该日期将重置。

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

如果你去

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.

一个解决方案可能是您的应用程序,在那里你可以存储每个用户ID 使用的 AccountPicker ,其首次安装与方法如上所述,在登录使用它们。您也可以使用应用授权服​​务。

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