gpt4 book ai didi

java - Android IabHelper 检查是否购买

转载 作者:行者123 更新时间:2023-11-30 11:15:41 26 4
gpt4 key购买 nike

如果购买了我要开启 Activity ,否则我要开启 Activity 进行购买。我进入 IabHelper 类来执行此操作,但没有得到任何结果。

我哪里错了?

代码 fragment :

private void Controlla_record_per_acquisto(){
SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();
String controllo = "SELECT COUNT(_id) FROM table";
Cursor c = db.rawQuery(controllo, null);

while (c.moveToNext()){
int numero_id = c.getInt(0);

if(numero_id >=1){

IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
if (result.isFailure()) {
// Handle error
return;
}
else if (purchase.getSku().equals(ITEM_SKU)) {

Intent intent = null;
intent = new Intent(getActivity(), Ce.class);
startActivity(intent);
}

}
};

}else {
Intent intent = null;
intent = new Intent(getActivity(), InAppBillingActivity.class);
startActivity(intent);
}
c.close();
db.close();
}
}

最佳答案

尝试使用此代码获取有关您的库存的数据。

不错的文章:

http://developer.android.com/training/in-app-billing/purchase-iab-products.html

调用方法:

mHelper = new IabHelper(this, base64EncodedPublicKey);

mHelper.enableDebugLogging(true);

mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {

if (!result.isSuccess()) {
return;
}

if (mHelper == null) return;
List<String> st = new ArrayList<String>();
st.add(ITEM_SKU);
mHelper.queryInventoryAsync(true,st,mGotInventoryListener);
}
});

如何查询元素的库存。

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

if (mHelper == null) return;

if (result.isFailure()) {
return;
}

if(inventory.hasPurchase(ITEM_SKU)) {
Intent intent = null;
intent = new Intent(getActivity(), Ce.class);
startActivity(intent);
}
}
};

关于java - Android IabHelper 检查是否购买,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25251781/

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