Android 播放计费库1.0-无连接
我正在尝试实现google新的Play Billing Library 1.0,但无法连接。它适用于旧的普通驱动器类 我总是得到responseCode=3/不可用 我在一个真实的设备上运行这个应用程序,它是作为alpha测试仪从googleplay下载的。 有什么想法吗Android 播放计费库1.0-无连接,android,play-billing-library,Android,Play Billing Library,我正在尝试实现google新的Play Billing Library 1.0,但无法连接。它适用于旧的普通驱动器类 我总是得到responseCode=3/不可用 我在一个真实的设备上运行这个应用程序,它是作为alpha测试仪从googleplay下载的。 有什么想法吗 public BillingManager(Activity activity, final BillingUpdatesListener updatesListener) { mActivity = activity
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 {
}
}
public BillingManager(活动活动,最终账单更新侦听器更新侦听器){
活动性=活动性;
mBillingUpdatesListener=updatesListener;
mBillingClient=BillingClient.newBuilder(mActivity).setListener(this.build();
startServiceConnection(新的可运行(){
@凌驾
公开募捐{
mBillingUpdatesListener.onBillingClientSetupFinished();
queryPurchases();
}
});
}
public void startServiceConnection(最终可运行executeOnSuccess){
mBillingClient.startConnection(新的BillingClientStateListener(){
@凌驾
已完成BillingSetupFinished(@BillingClient.BillingResponse int responseCode)上的公共无效{
if(responseCode==BillingClient.BillingResponse.OK){
连接错误=正确;
if(executeOnSuccess!=null){
executeOnSuccess.run();
}
}
mBillingClientResponseCode=响应代码;
}
@凌驾
公共无效onBillingServiceDisconnected(){
连接错误=错误;
}
});
}
public void initiatePurchaseFlow(最终字符串skuId,最终数组列表oldSkus,最终@BillingClient.SkuType字符串billingType){
Runnable purchaseFlowRequest=新的Runnable(){
@凌驾
公开募捐{
BillingFlowParams.Builder mParams=BillingFlowParams.newBuilder().setSku(skuId).setType(billingType).setOldSkus(oldSkus);
mBillingClient.launchBillingFlow(mActivity,mParams.build());
}
};
executeServiceRequest(purchaseFlowRequest);
}
私有void executeServiceRequest(可运行可运行){
如果(未连接){
runnable.run();
}否则{
startServiceConnection(可运行);
}
}
@凌驾
公共无效onPurchasesUpdated(int responseCode,@Nullable List purchases){
if(responseCode==BillingClient.BillingResponse.OK){
用于(采购:采购){
手工采购(采购);
}
mBillingUpdatesListener.onPurchasesUpdated(采购);
}else if(responseCode==BillingClient.BillingResponse.USER\u已取消){
}否则{
}
}
}
编辑:问题是,我将null作为ArrayList oldSkus传递。如果我没有旧SKU,有人能告诉我还有什么可以通过吗?如果我删除.setOldSkus,它会起作用,但我仍然想知道什么是正确的方法。如果您使用的是模拟器,请首先检查您是否启用了Google Play服务,是否安装了Play Store应用程序,是否允许您在那里购买应用程序。 但在真正的设备上与播放计费集成要容易得多 而Play Billing library对于所有开发人员错误(包括setOldSkus方法的问题)都相当详细。只需按照内部的建议启用它的日志 例如:
adb shell setprop log.tag.BillingClient VERBOSE
我将null传递给oldSkus,它工作正常,您的skuId与google play上的产品id匹配吗?嘿,原因很简单,我在模拟器上运行了它…是的,是模拟器。这似乎根本不起作用。