简体   繁体   English

通过 Play 商店在 Android 应用程序中唯一标识用户?

[英]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 的subscriptionpurchase ,就会调用此方法。 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.

相关问题 Android应用程序类别通过Play商店 - Android App Category via Play Store 将Android应用程序唯一地连接到​​PC上的Java Applet - Uniquely connect an android application to a java applet on pc Android 应用程序将在 Play 商店发布新版本时自动更新 - Android Application will auto update when a new version is released on play store 重新启动已上传到Google Play商店的Android应用程序 - Restarting Android application that has been uploaded to Google Play Store 由于违反用户隐私规定,Android应用已从Play商店中删除 - Android App removed from Play Store due user privacy violation 唯一标识testng中的每个测试调用 - uniquely identifying each test invocation in testng 在Android应用程序中存储用户设置的最合适方法是什么 - What is the most appropriate way to store user settings in Android application 当应用程序从 Play 商店强制更新时,如何保持 android 应用程序始终登录 state? - How to keep android applications always be login state when application get force update from play store? 当Android应用程序通过Google Play更新时,活动开始出现奇怪的异常 - Strange exception on activity start when android application was updated via Google Play 如何在用户只通过短信进行通信的应用程序中存储用户首选项? - How to store user preferences in an application where users only communicate via SMS messages?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM