java - Android IabHelper 检查是否购买

标签 java android google-api billing

如果购买了我要开启 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/

相关文章:

java - 我如何在这段代码中检查我的对的实际值? java

python - 收到错误 400 : redirect_uri_mismatch when trying to use OAuth2 with Google Sheets from a Django view

java - 如何使用 gwt-visualization 绘制连续图表

java - 通过数据库在两个 Java 应用程序之间同步

java - 在 toString 方法中尝试 Catch block

android - 以编程方式允许 super 用户权限

Android:onUpgrade 不在数据库升级时调用

android - 获取所有已安装的应用程序时过滤掉不可启动的应用程序

ios - Google YouTube API v3 iOS 应用 key ,403 错误代码

java - 与隐式构造函数和构造函数链接相关的混淆