Android In-App Purchase check buyer offline

后端 未结 2 1044
無奈伤痛
無奈伤痛 2020-12-31 22:55

I have implement in app purchase (managed) in my application using billing services when ever user wants to buy item he will make purchase request that required internet eve

相关标签:
2条回答
  • 2020-12-31 23:29

    Complete example of this technique is within TrivialDrive sample app and it's work for me, but Im thinking about offline case. Google Play app caches purchases and gives responses to the getPurchases(3, "pkg", "inapp", null) offline but is this works infinitly or there is something like a timeout for this cache...

    0 讨论(0)
  • 2020-12-31 23:38

    This is not safe. I would discourage you from implementing such a check this way. You should rather go for standard approach and use getPurchases() method. You can call this method at any time (even offline) and if a user has purchases, they will be returned back from that method. Here is a sample code:

    IInAppBillingService service; // initialize it first
    
    Bundle response = service.getPurchases(3, "you app package", "inapp", null);
    int responseCode = response.getInt(KEY_RESPONSE_CODE);
    if (responseCode == RESPONSE_OK) {
        ArrayList<String> purchases = response.getStringArrayList(KEY_INAPP_PURCHASE_ITEM_LIST);
        ...
    }
    

    Of curse you need to verify that purchases are signed with correct certificate and purchase state is not cancelled. But this is much safer than storing data in shared properties. Another advantage of this approach is that after user reinstalls the app, all purchases will be automatically available there too.

    0 讨论(0)
提交回复
热议问题