我正在尝试实施 google 的新 Play Billing Library 1.0,但我无法建立连接。它适用于旧的 Trivial Drive 课程。
我总是得到 responseCode = 3/UNAVAILABLE
我在真实设备上运行该应用程序,从 google play 作为 alpha 测试仪下载。有任何想法吗?
public BillingManager(Activity activity, final BillingUpdatesListener updatesListener) {
mActivity = activity;
mBillingUpdatesListener = updatesListener;
mBillingClient = BillingClient.newBuilder(mActivity).setListener(this).build();
startServiceConnection(new Runnable() {
@Override
public void run() {
mBillingUpdatesListener.onBillingClientSetupFinished();
queryPurchases();
}
});
}
public void startServiceConnection(final Runnable executeOnSuccess) {
mBillingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@BillingClient.BillingResponse int responseCode) {
if (responseCode == BillingClient.BillingResponse.OK) {
mIsServiceConnected = true;
if (executeOnSuccess != null) {
executeOnSuccess.run();
}
}
mBillingClientResponseCode = responseCode;
}
@Override
public void onBillingServiceDisconnected() {
mIsServiceConnected = false;
}
});
}
public void initiatePurchaseFlow(final String skuId, final ArrayList<String> oldSkus, final @BillingClient.SkuType String billingType) {
Runnable purchaseFlowRequest = new Runnable() {
@Override
public void run() {
BillingFlowParams.Builder mParams = BillingFlowParams.newBuilder().setSku(skuId).setType(billingType).setOldSkus(oldSkus);
mBillingClient.launchBillingFlow(mActivity, mParams.build());
}
};
executeServiceRequest(purchaseFlowRequest);
}
private void executeServiceRequest(Runnable runnable) {
if (mIsServiceConnected) {
runnable.run();
} else {
startServiceConnection(runnable);
}
}
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
if (responseCode == BillingClient.BillingResponse.OK) {
for (Purchase purchase : purchases) {
handlePurchases(purchase);
}
mBillingUpdatesListener.onPurchasesUpdated(mPurchases);
} else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {
} else {
}
}
}
编辑:问题是,我将 null 作为 ArrayList oldSkus 传递。如果我没有旧的 Skus,谁能告诉我还有什么要通过的吗?如果我删除 .setOldSkus,它会起作用,但我仍然想知道什么是正确的方法。