[英]Uniquely identifying the user in the Android application via the Play store?
I have an android application that does not have login / register structure but users can start subscription with in-app purchase.我有一个没有登录/注册结构但用户可以通过应用内购买开始订阅的 android 应用程序。
I want to be able to recognize the user on different devices where the user logs in with the same play store account.我希望能够在用户使用相同的 Play 商店帐户登录的不同设备上识别用户。 So I want to be able to uniquely identify a user through the play store account.所以我希望能够通过 Play 商店帐户唯一地识别用户。
Since my application is in the child and family category, I cannot access AccountManager-style sensitive data.由于我的应用程序属于儿童和家庭类别,因此我无法访问 AccountManager 样式的敏感数据。
How can I do that.我怎样才能做到这一点。 Does anyone have great ideas?有人有好主意吗?
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.这个库完美地处理Subscriptions
以及Purchases
和没有有效负载。 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.你只需要在你的 build.gradle 中放置implementation 'com.anjlab.android.iab.v3:library:1.0.44'
并且你对build.gradle
很好
When your build.gradle
is ready, implement BillingProcessor.IBillingHandler
with your activity
.当您的build.gradle
准备就绪时,使用您的activity
实施BillingProcessor.IBillingHandler
。
Then intialize your billing processor by placing this code in onCreate
.然后通过将此代码放入onCreate
来初始化您的计费处理器。
bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);
bp.initialize();
You will get the following override
methods,您将获得以下override
方法,
@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.这是诀窍, onPurchaseHistoryRestored
是您正在寻找的实际方法。 This method will get called whenever there is a subscription
or purchase
already available against a specific email.只要有针对特定 email 的subscription
或purchase
,就会调用此方法。 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
.不要忘记在您的Manifest
中添加此<uses-permission android:name="com.android.vending.BILLING" />
权限。
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.如果要查询在不同设备上登录同一个账号的用户的订阅状态,可以使用BillingClient.queryPurchases()接口查询订阅状态。 If the interface returns a subscription, it is within the subscription validity period, and you need to continue providing services.如果接口返回订阅,则在订阅有效期内,需要继续提供服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.