java—通过play store唯一地标识android应用程序中的用户?

sczxawaw  于 2021-07-03  发布在  Java
关注(0)|答案(2)|浏览(465)

我有一个android应用程序,没有登录/注册结构,但用户可以开始订阅应用程序内购买。
我希望能够识别不同设备上的用户,在这些设备上,用户使用相同的play store帐户登录。因此,我希望能够通过play store帐户唯一地标识用户。
由于我的应用程序属于“儿童和家庭”类别,因此我无法访问accountmanager样式的敏感数据。
我怎么能那样做。有人有好主意吗?

uxh89sit

uxh89sit1#

有一个伟大的图书馆,我希望能帮助你解决你的问题,因为我已经在一些产品中使用它。你可以试试这个图书馆
这个图书馆能很好地处理 Subscriptions 以及 Purchases 有无有效载荷。你只需要把 implementation 'com.anjlab.android.iab.v3:library:1.0.44' 在你的 build.gradle 你可以走了。
当你的 build.gradle 准备就绪,实施 BillingProcessor.IBillingHandler 用你的 activity .
然后将此代码放入 onCreate .

  1. bp = new BillingProcessor(this, "YOUR LICENSE KEY FROM GOOGLE PLAY CONSOLE HERE", this);
  2. bp.initialize();

您将获得以下信息 override 方法,

  1. @Override
  2. public void onBillingInitialized() {
  3. /*
  4. * Called when BillingProcessor was initialized and it's ready to purchase
  5. */
  6. }
  7. @Override
  8. public void onProductPurchased(String productId, TransactionDetails details) {
  9. /*
  10. * Called when requested PRODUCT ID was successfully purchased
  11. */
  12. }
  13. @Override
  14. public void onBillingError(int errorCode, Throwable error) {
  15. /*
  16. * Called when some error occurred. See Constants class for more details
  17. *
  18. * Note - this includes handling the case where the user canceled the buy dialog:
  19. * errorCode = Constants.BILLING_RESPONSE_RESULT_USER_CANCELED
  20. */
  21. }
  22. @Override
  23. public void onPurchaseHistoryRestored() {
  24. /*
  25. * Called when purchase history was restored and the list of all owned PRODUCT ID's
  26. * was loaded from Google Play
  27. */
  28. }

这是诀窍, onPurchaseHistoryRestored 是你要找的实际方法。只要有错误,就会调用此方法 subscription 或者 purchase 已针对特定电子邮件提供。这个库将自动为您处理它。如果对你有帮助就告诉我。
别忘了加上这个 <uses-permission android:name="com.android.vending.BILLING" /> 在您的 Manifest .

展开查看全部
zi8p0yeb

zi8p0yeb2#

如果要查询在不同设备上登录到同一帐户的用户的订阅状态,可以使用billingclient.querypurchases()接口查询订阅状态。如果接口返回订阅,则它在订阅有效期内,您需要继续提供服务。

相关问题