2

Is there any android api to get information about the purchase of the app? I don't talk about in-app purchases. Just the Plain APP-Purchase.

I need any unique identifier like an transaction id or something like that.

Cœur
  • 32,421
  • 21
  • 173
  • 232
wutzebaer
  • 12,445
  • 18
  • 77
  • 144
  • Sorry, I am not clear about App-Purchase. Are you asking about API for getting information (price, availability , country ..etc) regarding to Google play app's ? – Ravi Jaggarapu Dec 17 '15 at 12:58
  • no... the app itself must identify the purchase of itself, because the app should do something only once, even when uninstalled and re installed, so we must be able to check if this action has already been done for this purchase – wutzebaer Dec 17 '15 at 14:51
  • As mentioned below, I'm not sure, if it's possible out of the box. But if I were you, I'd implement some tiny API endpoint on your server side and sends it hashed version of the user's accountId (see [Accessing Google Account Id /username via Android](http://stackoverflow.com/questions/2245545/accessing-google-account-id-username-via-android) ) and Timestamp-response of initial call of this method for this particular user Id (i.e. once he changed his phone - you'll still track him). I don't know if it can be considered as an answer to you question.(if yes-i'll convert it into answer) – Konstantin Loginov Jan 04 '16 at 11:19
  • @Konstatin the PeopleApi seems to be deprecated and the AccountManager does not show which account bought the app, but we're checking the follow up api: "Plus Api" – wutzebaer Jan 04 '16 at 12:40

4 Answers4

1

As per my understanding of question you want to get information of your app buyers or you want to check particular user's purchase status for your app.

AFAIK : As of now I can't able to see any buyers info for your android application purchase. Reference : https://support.google.com/googleplay/android-developer/answer/6056620?hl=en

But in past may be we were able to see such information. Reference : Android Market (Google Play). Get buyer information

Community
  • 1
  • 1
jignesh
  • 1,214
  • 1
  • 10
  • 22
1

As far as I know there is no way to persist this information across app uninstall/reinstalls. You can get the installation timestamp but this will be reset when reinstalling.

However, a workable solution may be to set a flag in SharedPreferences and save the data using Android Backup (http://developer.android.com/guide/topics/data/backup.html#SharedPreferences)

mlidal
  • 981
  • 13
  • 24
  • is the user able to delete this backed up data? – wutzebaer Jan 04 '16 at 09:29
  • Not as far as I can see from the documentation – mlidal Jan 04 '16 at 09:36
  • http://developer.android.com/google/backup/index.html "When a user disables backup, Android Backup Service deletes all saved backup data." – wutzebaer Jan 04 '16 at 10:00
  • I missed that sentence. In this case I think the only reliable solution is to setup your own server and have the app register itself during the first installation. – mlidal Jan 04 '16 at 12:12
  • but when the user reinstalls the app he can repeat the registration - which is the thing i want to avoid – wutzebaer Jan 04 '16 at 12:18
  • In this case you need to have the app check with your server if the user has already registered (a check for the google account name should be easy to implement) – mlidal Jan 04 '16 at 12:22
  • "a check for the google account name" this is exactly what i would need, a reliable information which google-user is currently acting... can you post an answert with that? – wutzebaer Jan 04 '16 at 12:27
1

As mentioned in other answers, it looks like there's no public API for it. (I believe, the reason for it is that by default - once user starts the app - he has already got if from Google Play. So in the ideal world, there should be no need for this check)

If I were you, I'd implement some tiny API endpoint on your server side and sends it hashed version of the user's accountId (see Accessing Google Account Id /username via Android ) and Timestamp-response(or any other reasonable data back) of initial call of this method for this particular user Id (i.e. once he changed his phone - you'll still track him).

To get current Account do this:

    Account[] accounts = AccountManager.get(this).getAccountsByType("com.google"); 
    if (accounts.length != 0) {
         String myEmailid=accounts[0].toString();
    }

(taken from here)

Tested on API 19 and API 23(In Android M it requires a bit extra work due to permission-check)

Community
  • 1
  • 1
Konstantin Loginov
  • 14,994
  • 5
  • 54
  • 90
  • accounts[0] is always the active one? – wutzebaer Jan 04 '16 at 12:53
  • @wutzebaer From what I can tell - I've **tested** it with my two Google-accounts (on 2 different OS versions - **API 19** and **API 23** and 2 different devices) - it works like a charm. To say, that it works always - I'm checking android source code for some proof. – Konstantin Loginov Jan 04 '16 at 13:47
  • seems that it only represents the order of the account list, but i can switch the user in google play, without changing this order – wutzebaer Jan 04 '16 at 16:41
  • @wutzebaer That's obviously true: if you don't switch between your accounts, but adding secondary Google account as an extra account in settings, and use Google Play as a secondary user, you'll still run your app as _primary_ user. **IF** you really caring about this case, you have to ask user during app start with which account he wants to start your app. – Konstantin Loginov Jan 04 '16 at 16:53
1

The most reliable way would be to create your own (web-)service and have the app register itself with the google user name (How do I retrieve the logged in Google account on android phones?), and check the registration on later reinstall.

Community
  • 1
  • 1
mlidal
  • 981
  • 13
  • 24
  • the solution does not include how to detect which of the google accounts has purchased the app if multiple are registered – wutzebaer Jan 04 '16 at 12:33
  • @wutzebaer that's "by design". If you have 2 Google accounts and buy something with one of them, you shouldn't have access to the purchase from another one (otherwise, it'd be a hole in security and would lead to pirating of the apps). So you have to rely on the "current" account user runs the app. – Konstantin Loginov Jan 04 '16 at 12:37
  • and how can i determine the current account? – wutzebaer Jan 04 '16 at 12:40
  • @wutzebaer added into my answer - you'll need to take first account with type "com.google" – Konstantin Loginov Jan 04 '16 at 12:45
  • The main account is "probably" the first one (from other SO questions), but I think you need to test this for yourself before relying on it. – mlidal Jan 04 '16 at 12:47