private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {@Overridepublic void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {// To be implemented in a later section.}
};
4.3初始化SDK后,需要与 Google Play 建立连接,使用startConnection()方法,startConnection是异步进行,这个时候需要一个BillingClientStateListener进行回调连接的结果,当连接完成会走onBillingSetupFinished()回调,通过返回的billingResult.getResponseCode()去判断是否真正的链接成功,这个code 有下面几个值,这个BillingClientStateListener还有一个Google Play 失去连接的回调,这个时候我们需要实现重试逻辑,就是再次调用startConnection()函数。
public void startConnection() {mBillingClient.startConnection(new BillingClientStateListener() {@Overridepublic void onBillingSetupFinished(BillingResult billingResult) {if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {// The BillingClient is ready. You can query purchases here.queryProductDetailsParams();queryOldOrder();}}@Overridepublic void onBillingServiceDisconnected() {// Try to restart the connection on the next request to// Google Play by calling the startConnection() method.}});}
4.4 获取商品
当startConnection()回调成功时,这个时候我们就可以根据ProductId去Google Play获取具体的商品了,这个时候一般会通过API去自己的Server 获取一个ProductIdList,然后根据后台返回的productId去Google Play 获取商品详情。
// The BillingClient is ready. You can query purchases here.List<String> subscribeSkuList = new ArrayList<>();subscribeSkuList.add("Subscribe01");subscribeSkuList.add("Subscribe01");subscribeSkuList.add("Subscribe01");SkuDetailsParams.Builder subscribeParams = SkuDetailsParams.newBuilder();subscribeParams.setSkusList(subscribeSkuList).setType(BillingClient.SkuType.SUBS);mBillingClient.querySkuDetailsAsync(subscribeParams.build(), new SkuDetailsResponseListener() {@Overridepublic void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {// Process the result.Log.i(TAG, "querySkuDetailsAsync 2 onSkuDetailsResponse billingResult.getResponseCode : " + billingResult.getResponseCode() + " skuDetailsList :" + skuDetailsList);mSubscribeSkuDetailsHashMap.clear();if (skuDetailsList != null && skuDetailsList.size() > 0) {for (SkuDetails skuDetails : skuDetailsList) {mSubscribeSkuDetailsHashMap.put(skuDetails.getSku(), skuDetails);}}}});
当商品查询成功后就可以结合Server返回的商品信息给用户展示商品列表了
注意:有些 Android 设备安装的可能是旧版 Google Play 商店应用,不支持订阅等某些商品类型。在您的应用进入结算流程之前,您可以调用 isFeatureSupported() 以确定设备是否支持您要销售的商品。如需查看可支持的商品类型的列表,请参阅 BillingClient.FeatureType。
// An activity reference from which the billing flow will be launched.
Activity activity = ...;ImmutableList productDetailsParamsList =ImmutableList.of(ProductDetailsParams.newBuilder()// retrieve a value for "productDetails" by calling queryProductDetailsAsync().setProductDetails(productDetails)// to get an offer token, call ProductDetails.getSubscriptionOfferDetails()// for a list of offers that are available to the user.setOfferToken(selectedOfferToken).build());BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().setProductDetailsParamsList(productDetailsParamsList).build();// Launch the billing flow
BillingResult billingResult = billingClient.launchBillingFlow(activity, billingFlowParams);
4.6购买成功的回调
在咱们4.2初始化SDK的时候添加了一个PurchasesUpdatedListener,当用户购买成功后Google Play 会调用 onPurchasesUpdated(),我们根据responseCode去区分用户购买成功与否.
void handlePurchase(Purchase purchase) {// Purchase retrieved from BillingClient#queryPurchasesAsync or your PurchasesUpdatedListener.Purchase purchase = ...;// Verify the purchase.// Ensure entitlement was not already granted for this purchaseToken.// Grant entitlement to the user.ConsumeParams consumeParams =ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();ConsumeResponseListener listener = new ConsumeResponseListener() {@Overridepublic void onConsumeResponse(BillingResult billingResult, String purchaseToken) {if (billingResult.getResponseCode() == BillingResponseCode.OK) {// Handle the success of the consume operation.}}};billingClient.consumeAsync(consumeParams, listener);
}
消费订阅商品:订阅的处理方式与非消耗型商品类似。您可以使用 Google Play 结算库中的 BillingClient.acknowledgePurchase() 或 Google Play Developer API 中的 Purchases.Subscriptions.Acknowledge 确认订阅。所有初始订阅购买交易都需要确认。订阅续订不需要确认
Google Play 允许客户在一笔交易中购买多件相同的应用内商品,只需在购物车中指定商品数量即可(4.0 及更高版本的 Google Play 结算库支持该功能)。应用应根据指定购买数量来处理多件购买并授予权利。注意:多件购买适用于消耗型应用内商品,即可以购买、消耗及再次购买的产品。请勿为不支持重复购买的商品启用该功能。
为了实现多件购买,应用的配置逻辑需要检查商品数量。可以从以下 API 访问 quantity 字段:
Google Play 结算库中的 getQuantity()。
Google Play Developer API 中的 Purchases.products.quantity。
添加用于处理多件购买的逻辑后,需要在 Google Play 管理中心的应用内商品管理页面上为相应的商品启用多件购买功能。
注意:请确保应用接受多件购买,然后再在 Play 管理中心启用该功能。您能需要强制更新到提供支持的应用版本,然后才能对商品启用该功能。
[root@admin]# resize2fs /dev/vda1resize2fs 1.42.9 (28-Dec-2013)Filesystem at /dev/vda1 is mounted on /; on-line resizing requiredold_desc_blocks = 2, new_desc_blocks = 7The filesystem on /dev/vda1 is now 26214139 blocks long.
========================== This is a notification that your Google Play Publisher account has been terminated.
REASON FOR TERMINATION: Prior violations of the Content Policy and Developer Distribution Agreement by this or associated accounts as outlined in previous emails sent to the registered email address(es) of the Publisher account(s).
Please note that Google Play Publisher suspensions are associated with developers, and may span multiple account registrations and related Google services. If you feel we have made an error, you can visit the Google Play Help Center article for additional information regarding this termination.
Do not attempt to register a new developer account. We will not be restoring your account at this time.
在 manifest.json 文件的 “App常用其它设置” 中可勾选开启(注意HBuilder X 2.4以上为默认勾选),需提交云端打包才会生效
在低版本的HBuilder是默认勾选,可以将这个勾选给去掉,重新打包后提交应用到AppStore。
Guideline 5.1.2 - Legal - Privacy - Data Use and Sharing
We noticed you do not use App Tracking Transparency to request the user's permission before tracking their activity across apps and websites. The app privacy information you provided in App Store Connect indicates you collect data in order to track the user, including Device ID and Precise Location.
Starting with iOS 14.5, apps on the App Store need to receive the user’s permission through the AppTrackingTransparency framework before collecting data used to track them. This requirement protects the privacy of App Store users.
Next Steps
Here are two ways to resolve this issue:
- You can remove the tracking functionality from your app and update your app privacy information in App Store Connect.
- If you decide to continue tracking users, you must implement App Tracking Transparency and request permission before collecting data used to track the user or device.
Resources
- See Frequently Asked Questions about the new requirements for apps that track users.
- Learn more about designing appropriate permission requests.