gpt4 book ai didi

java - Android Google Pay 结算 - 响应 4 : ITEM_UNAVAILABLE

转载 作者:行者123 更新时间:2023-12-01 16:18:59 27 4
gpt4 key购买 nike

我正在尝试集成 Google Play 结算。

这是我的 onCreate :

private final static String     TAG = "MainActivity" ;
private final static String ITEM_SKU_SUBSCRIBE = "sub_example" ;
private final static String PREF_FILE = "shared_prefs" ;
private final static String SUBSCRIBE_KEY = "subscribe" ;

private BillingClient billingClient ;

private TextView premiumContent ;
private TextView subscriptionStatus ;
private Button purchaseButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

premiumContent = findViewById(R.id.premium_content) ;
subscriptionStatus = findViewById(R.id.subscription_status) ;
purchaseButton = findViewById(R.id.button) ;

billingClient = BillingClient.newBuilder(this)
.enablePendingPurchases()
.setListener(this)
.build() ;
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(BillingResult billingResult) {
Log.i(TAG, "onBillingSetupFinished ; billing response code == " + billingResult.getResponseCode());
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Purchase.PurchasesResult queryPurchase = billingClient.queryPurchases(SUBS);
List<Purchase> queryPurchases = queryPurchase.getPurchasesList();
if (queryPurchases != null && queryPurchases.size() > 0) {
handlePurchases(queryPurchases);
} else {
saveSubscribeValueToPref(false);
}
} else {
Log.e(TAG, "ELSE : " + billingResult.getDebugMessage()) ;
}
}

@Override
public void onBillingServiceDisconnected() {
Toast.makeText(getApplicationContext(), "Service disconnected",
Toast.LENGTH_SHORT).show() ;
}
});

if (getSubscribeValueFromPref()) {
purchaseButton.setVisibility(View.GONE);
premiumContent.setVisibility(View.VISIBLE);
subscriptionStatus.setText("Subscription Status : Subscribed");
} else {
premiumContent.setVisibility(View.GONE);
purchaseButton.setVisibility(View.VISIBLE);
subscriptionStatus.setText("Subscription Status : Not Subscribed");
}

purchaseButton.setText("Load products");
purchaseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
subscribe();
}
});
}

当我点击purchaseButton时,我调用subscribe功能。

基本上它只是调用一个函数initiatePurchase如果billingClient.isReady()返回true ,并初始化billingClient在另一种情况下。

这是我的initiatePurchase功能:

private void        initiatePurchase() {
List<String> skuList = new ArrayList<>() ;
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder() ;

skuList.add(ITEM_SKU_SUBSCRIBE);
params.setSkusList(skuList).setType(SUBS);
BillingResult billingResult = billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS) ;
Log.i(TAG, "Billing response code == " + billingResult.getResponseCode()) ;
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Log.i(TAG, "Billing response code is OK");
billingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
Log.i(TAG, "onSkuDetailsResponse ; billing result response code == " + billingResult.getResponseCode());
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Log.i(TAG, "Billing response code OK") ;
if (skuDetailsList != null) {
for (int i = 0 ; i < skuDetailsList.size() ; i++) {
Log.i(TAG, "Loop INDEX " + i + " ; SkuDetails == " + skuDetailsList.get(i).getTitle()) ;
}
}
if (skuDetailsList != null && skuDetailsList.size() > 0) {
Log.i(TAG, "skuDetailsList is not null or empty");
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetailsList.get(0))
.build();
Log.i(TAG, "Flow Params = " + flowParams.getAccountId() + " | " + flowParams.getSku());
BillingResult billingFlowResult = billingClient
.launchBillingFlow(MainActivity.this, flowParams);
Log.i(TAG, "billingFlowResult == " + billingFlowResult.getResponseCode() + " | " + billingFlowResult.getDebugMessage()) ;
} else {
Toast.makeText(getApplicationContext(),
"Item not found", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(),
"Error - " + billingResult.getDebugMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
} else {
Toast.makeText(getApplicationContext(),
"Sorry, subscription not supported. Please update Play Store",
Toast.LENGTH_SHORT).show();
}
}

好像是去onSkuDetailsResponse ,带有计费响应代码 OK。

我在 skuDetailsList 中循环我得到 sub_example ,这是我的ITEM_SKU_SUBSCRIBE (以及我的 Play 商店控制台上的那个);所以我的skuDetailsList不为 null 或为空。

但是,这是我的日志输出:

I/MainActivity: Billing response code == 0
Billing response code is OK
I/MainActivity: onSkuDetailsResponse ; billing result response code == 0
Billing response code OK
Loop INDEX 0 ; SkuDetails == Monthly sub (Test Billing)
skuDetailsList is not null or empty
I/MainActivity: Flow Params = null | sub_example
I/MainActivity: billingFlowResult == 0 | null
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@cb159f0

Google Play error

当我单击“确定”按钮时,会出现有趣的日志:

W/ProxyBillingActivity: Activity finished with resultCode 0 and billing's responseCode: 4
W/BillingHelper: Couldn't find purchase lists, trying to find single data.
W/BillingHelper: Received a bad purchase data.
Couldn't find single purchase data as well.

我查找了BillingClient.class我发现int ITEM_UNAVAILABLE = 4;interface BillingResponseCode

  • 我正在签名的发布配置中编译并启动此应用
  • 该应用的旧版本已在 Google Play 上发布 Alpha 版本(但版本代码和版本名称相同)
  • 我的 Google Play 帐户位于测试人员列表中,这是我今天为此创建的 @gmail 地址(我的其他 Google 帐户没有 @gmail 地址 - 嗯,也不起作用)
  • 我昨天在 Google Play 管理中心创建了此订阅
  • 我的应用程序自昨天起已在 alpha 版本中发布(未审核)。
  • 我遵循了本教程:https://programtown.com/how-to-make-in-app-purchase-subscription-in-android-using-google-play-billing-library/

谢谢

最佳答案

看来唯一能做的就是等待......
今天早上成功了。
计算 2 天后,您的应用内付款即可在应用上使用。

关于java - Android Google Pay 结算 - 响应 4 : ITEM_UNAVAILABLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62320895/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com