我有一个android应用程序,没有登录/注册结构,但用户可以开始订阅应用程序内购买。我希望能够识别不同设备上的用户,在这些设备上,用户使用相同的play store帐户登录。因此,我希望能够通过play store帐户唯一地标识用户。由于我的应用程序属于“儿童和家庭”类别,因此我无法访问accountmanager样式的敏感数据。我怎么能那样做。有人有好主意吗?
uxh89sit1#
有一个伟大的图书馆,我希望能帮助你解决你的问题,因为我已经在一些产品中使用它。你可以试试这个图书馆这个图书馆能很好地处理 Subscriptions 以及 Purchases 有无有效载荷。你只需要把 implementation 'com.anjlab.android.iab.v3:library:1.0.44' 在你的 build.gradle 你可以走了。当你的 build.gradle 准备就绪,实施 BillingProcessor.IBillingHandler 用你的 activity .然后将此代码放入 onCreate .
Subscriptions
Purchases
implementation 'com.anjlab.android.iab.v3:library:1.0.44'
build.gradle
BillingProcessor.IBillingHandler
activity
onCreate
bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);bp.initialize();
bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);
bp.initialize();
您将获得以下信息 override 方法,
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 */ }
@Override
public void onBillingInitialized() {
/*
* Called when BillingProcessor was initialized and it's ready to purchase
*/
}
public void onProductPurchased(String productId, TransactionDetails details) {
* Called when requested PRODUCT ID was successfully purchased
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
public void onPurchaseHistoryRestored() {
* Called when purchase history was restored and the list of all owned PRODUCT ID's
* was loaded from Google Play
这是诀窍, onPurchaseHistoryRestored 是你要找的实际方法。只要有错误,就会调用此方法 subscription 或者 purchase 已针对特定电子邮件提供。这个库将自动为您处理它。如果对你有帮助就告诉我。别忘了加上这个 <uses-permission android:name="com.android.vending.BILLING" /> 在您的 Manifest .
onPurchaseHistoryRestored
subscription
purchase
<uses-permission android:name="com.android.vending.BILLING" />
Manifest
zi8p0yeb2#
如果要查询在不同设备上登录到同一帐户的用户的订阅状态,可以使用billingclient.querypurchases()接口查询订阅状态。如果接口返回订阅,则它在订阅有效期内,您需要继续提供服务。
2条答案
按热度按时间uxh89sit1#
有一个伟大的图书馆,我希望能帮助你解决你的问题,因为我已经在一些产品中使用它。你可以试试这个图书馆
这个图书馆能很好地处理
Subscriptions
以及Purchases
有无有效载荷。你只需要把implementation 'com.anjlab.android.iab.v3:library:1.0.44'
在你的build.gradle
你可以走了。当你的
build.gradle
准备就绪,实施BillingProcessor.IBillingHandler
用你的activity
.然后将此代码放入
onCreate
.您将获得以下信息
override
方法,这是诀窍,
onPurchaseHistoryRestored
是你要找的实际方法。只要有错误,就会调用此方法subscription
或者purchase
已针对特定电子邮件提供。这个库将自动为您处理它。如果对你有帮助就告诉我。别忘了加上这个
<uses-permission android:name="com.android.vending.BILLING" />
在您的Manifest
.zi8p0yeb2#
如果要查询在不同设备上登录到同一帐户的用户的订阅状态,可以使用billingclient.querypurchases()接口查询订阅状态。如果接口返回订阅,则它在订阅有效期内,您需要继续提供服务。