Reputation: 543
I have an android application that does not have login / register structure but users can start subscription with in-app purchase.
I want to be able to recognize the user on different devices where the user logs in with the same play store account. So I want to be able to uniquely identify a user through the play store account.
Since my application is in the child and family category, I cannot access AccountManager-style sensitive data.
How can I do that. Does anyone have great ideas?
Upvotes: 3
Views: 297
Reputation: 31
There is a great library which I hope will help you solve your problem as I'm already using it in some products. You can try This library
This library perfectly handles Subscriptions
as well as Purchases
with and without payload. you just have to place implementation 'com.anjlab.android.iab.v3:library:1.0.44'
in your build.gradle
and you are good to go.
When your build.gradle
is ready, implement BillingProcessor.IBillingHandler
with your activity
.
Then intialize your billing processor by placing this code in onCreate
.
bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);
bp.initialize();
You will get the following override
methods,
@Override
public void onBillingInitialized() {
/*
* Called when BillingProcessor was initialized and it's ready to purchase
*/
}
@Override
public void onProductPurchased(String productId, TransactionDetails details) {
/*
* Called when requested PRODUCT ID was successfully purchased
*/
}
@Override
public void onBillingError(int errorCode, Throwable error) {
/*
* Called when some error occurred. See Constants class for more details
*
* Note - this includes handling the case where the user canceled the buy dialog:
* errorCode = Constants.BILLING_RESPONSE_RESULT_USER_CANCELED
*/
}
@Override
public void onPurchaseHistoryRestored() {
/*
* Called when purchase history was restored and the list of all owned PRODUCT ID's
* was loaded from Google Play
*/
}
Here is the trick, onPurchaseHistoryRestored
is the actual method you are looking for. This method will get called whenever there is a subscription
or purchase
already available against a specific email. This library will automatically handle it for you. Let me know if it help you.
Don't forget to add this <uses-permission android:name="com.android.vending.BILLING" />
permission in your Manifest
.
Upvotes: 1
Reputation: 34027
If you want to query the subscription status of users who log in to the same account on different devices, you can use the BillingClient.queryPurchases() interface to query the subscription status. If the interface returns a subscription, it is within the subscription validity period, and you need to continue providing services.
Upvotes: 0