无法使用com.android.billingClient:计费获取SkuDetail
原学程将引见没法应用com.android.billingClient:计费夺取SkuDetail的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。
成绩描写
我正在为Google Pay开辟1款游戏。如今是运用内购置的时刻了,我遵守了doc,但是我没法从代码中夺取SkuDetail
。
我应用库com.android.billingclient:billing:一.0
。
public void queryProductList(String product) {
List<String> skuList = new ArrayList<>();
skuList.add(product);
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
billingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int billingResult,
List<SkuDetails> skuDetailsList) {
if (billingResult == 0) {
Log.i(TAG, "getResponseCode ok");
if (skuDetailsList == null) {
Log.i(TAG, "skuDetailsList null");
} else {
Log.i(TAG, "skuDetailsList not null:" + skuDetailsList.size());// size is always 0
}
}
}
});
}
推举谜底
这是我用于填充SkuDetail的项目代码。您不妨停止1些编纂以及应用。
public void startServiceForConnectInBilling(String billing_period_of_product_一) {
this.product一 = billing_period_of_product_一;
myBillingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
try {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
isServiceConnected = true;
if (areSubscriptionsSupported()) {
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(billing_period_of_product_一);
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(arrayList).setType(BillingClient.SkuType.SUBS);
Runnable queryRequest = () -> myBillingClient.querySkuDetailsAsync(params.build(), (billingResult一, skuDetailsList) -> {
if (billingResult一.getResponseCode() != BillingClient.BillingResponseCode.OK) {
if (BuildConfig.DEBUG)
Log.e(TAG, "Error billing:" + billingResult一.getDebugMessage());
} else if (skuDetailsList != null && skuDetailsList.size() > 0) {
skuResultList.addAll(skuDetailsList);
if (SharedPreferenceHelper.getSharedPreferenceBoolean(context, AppConstants.GOOGLE_ON_OFF, false))
checkCondition();
}
});
executeServiceRequest(queryRequest);
}
}
} catch (Exception e) {
e.getMessage();
}
}
@Override
public void onBillingServiceDisconnected() {
}
});
}
private void executeServiceRequest(Runnable runnable) {
if (isServiceConnected) {
runnable.run();
} else {
// If billing service was disconnected, we try to reconnect 一 time.
// (feel free to introduce your retry policy here).
startServiceForConnectInBilling(product一);
}
}
private boolean areSubscriptionsSupported() {
if (myBillingClient == null) {
if (BuildConfig.DEBUG)
Log.e(TAG, "Billing client was null and quitting");
return false;
}
BillingResult responseCode = myBillingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS);
if (responseCode.getResponseCode() != BillingClient.BillingResponseCode.OK) {
if (BuildConfig.DEBUG)
Log.e(TAG,
"areSubscriptionsSupported() got an error response: " + responseCode);
}
return responseCode.getResponseCode() == BillingClient.BillingResponseCode.OK;
}
佳了闭于没法应用com.android.billingClient:计费夺取SkuDetail的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。