Android 帐单 - 我收到响应代码 5

Fra*_*ina 5 java android in-app-purchase google-play

我让我的应用内计费工作,但后来我移动了一些代码以获得更大的可扩展性,但它坏了。本质上,我试图做的是为我的插件制作一个适配器,以便以后可以更轻松地将它们添加到更少的编程工作中。我的项目在清单中具有计费权限,并且配置为在 Google Play 商店中计费,因此这不是问题。

广告活动

public class AdOnsActivity extends AppCompatActivity {
    private IInAppBillingService mService;
    private ServiceConnection mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
        }
    };

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

        Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

        listAdOns = findViewById(R.id.listAdOns);

        Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override
            public void run() {
                try {
                    ...
                    listAdOns.setAdapter(new AdOnAdapter(AdOnsActivity.this, json.getJSONArray("adOns"), mService));
                } catch (Exception e) {
                    Toast.makeText(AdOnsActivity.this, getResources().getString(R.string.error_load_ad_ons), Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                    finish();
                }
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

AdOnAdapter

public class AdOnAdapter extends BaseAdapter {
    public AdOnAdapter(Activity activity, JSONArray adOns, IInAppBillingService mService) throws RemoteException {
        Bundle querySkus = new Bundle();

        this.activity = activity;
        this.adOns = adOns;
        this.mService = mService;

        skuDetails = mService.getSkuDetails(3, activity.getPackageName(), "inapp", querySkus);
        responseDetails = skuDetails.getInt("RESPONSE_CODE");
        ownedItems = mService.getPurchases(3, activity.getPackageName(), "inapp", null);
        responseOwned = ownedItems.getInt("RESPONSE_CODE");
    }
Run Code Online (Sandbox Code Playgroud)

Nic*_*cue 4

此处列出了所有响应代码。

5 表示您正在使用无效参数调用 API。您以某种方式破坏了 API 调用。也许可以比较新旧版本代码下的 API 调用内容(您正在使用源代码控制吗?)。

  • 0.BILLING_RESPONSE_RESULT_OK:成功
  • 1. BILLING_RESPONSE_RESULT_USER_CANCELED:用户按回或取消对话框
  • 2. BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE:网络连接已关闭
  • 3. BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE:请求的类型不支持计费 API 版本
  • 4. BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE:请求的产品无法购买
  • 5. BILLING_RESPONSE_RESULT_DEVELOPER_ERROR:向 API 提供的参数无效。此错误还可能表明应用程序未正确签名或在 Google Play 中正确设置应用内结算,或者在其清单中没有必要的权限
  • 6. BILLING_RESPONSE_RESULT_ERROR:API 操作期间发生致命错误
  • 7. BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED:由于商品已被拥有而无法购买
  • 8. BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED:由于项目不被拥有而导致消费失败