Android In-App Purchase check buyer offline

后端 未结 2 1070
無奈伤痛
無奈伤痛 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: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 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.

提交回复
热议问题