我已经搜索了几个小时试图弄清楚这一点。这是我到目前为止所做的。(注:我在 Android Studio 中开发)
- 生成一个签名的 APK 并上传到我的开发者控制台
- 制作应用内产品并激活它
- 向我的清单添加了计费权限
- 广泛梳理 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 之后再也没有任何东西:开始应用内计费设置。