0

我已经搜索了几个小时试图弄清楚这一点。这是我到目前为止所做的。(注:我在 Android Studio 中开发)

  1. 生成一个签名的 APK 并上传到我的开发者控制台
  2. 制作应用内产品并激活它
  3. 向我的清单添加了计费权限
  4. 广泛梳理 Stack 以尝试发现类似的问题。

基本上在 logcat 中,我看到 IABHelper 开始设置,但在任何时候都不会完成。(监听器永远不会收到回调)

private static final String TAG = "Preference Activity";
private static final String SKU_PRO = "desk.clock.pro.license";
static final int RC_REQUEST = 10001;
IabHelper mHelper;
private boolean mIsPremium;
private ArrayList<Preference> proSettings;
IInAppBillingService mService;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    bindService(new
            Intent("com.android.vending.billing.InAppBillingService.BIND"),
            mServiceConn, Context.BIND_AUTO_CREATE);
    proSettings = new ArrayList<Preference>();
    ActionBar b = getActionBar();
    b.setDisplayHomeAsUpEnabled(true);
    colorListener();
    textureListener();
    bgColorListener();
    onPresetListener();
    gradListener();


    String base64Key = "[my key from dev console]";
    bindService(new
            Intent("com.android.vending.billing.InAppBillingService.BIND"),
            mServiceConn, Context.BIND_AUTO_CREATE);
    mHelper = new IabHelper(this, base64Key);
    mHelper.enableDebugLogging(true);
    Log.d(TAG, "Starting setup");
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
        public void onIabSetupFinished(IabResult result) {
            if (!result.isSuccess()) {
                // Oh noes, there was a problem.
                Log.d(TAG, "Problem setting up In-app Billing: " + result);
            }
            Log.d(TAG, "Setting up success");

            Log.d(TAG, "querying inventory");
            mHelper.queryInventoryAsync(mGotInventoryListener);
            Log.d(TAG, "queried");
        }
    });
 IabHelper.QueryInventoryFinishedListener mGotInventoryListener
        = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result,
                                         Inventory inventory) {

        if (result.isFailure()) {
            // handle error here
            mIsPremium = false;
            disableProAndRevertSettings();
        }
        else {
            // does the user have the premium upgrade?
            mIsPremium = inventory.hasPurchase(SKU_PRO);
            if(mIsPremium) {
                enableProSettings();
            }else {
                disableProAndRevertSettings();
            }
        }
    }
};
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);
    }
};
 //rest of my activity

我在我的 logcat 中得到了这条线,但在 10-06 15:46:44.485 20787-20787/com.ssa.digitaldeskclock D/IabHelper 之后再也没有任何东西:开始应用内计费设置。

4

1 回答 1

0

通过获取 IAB v3 示例的所有 util 类的新版本来解决问题。我将所有新文件添加到我的 util 目录中,它完美无缺。希望这可以帮助其他人。请参阅此链接以获取源 https://code.google.com/p/marketbilling/source/browse/v3/src/com/example/android/trivialdrivesample/util/IabHelper.java?r=5f6b7abfd0534acd5bfc7c14436f4500c99e0358

于 2013-10-07T08:28:07.810 回答