Android IAP:处理已购买的物品

问题描述:

我试图在应用程序购买中使用Android。我正在使用官方文档和util(Base64等)。我正在使用管理项目。 我在哪里以及如何处理已经购买的物品? (我将布尔值设置为true并将其保存为共享首选项,但是如果我删除并安装该应用程序,则共享首选项将丢失。)Android IAP:处理已购买的物品

现在,如果我单击“购买按钮”,则会收到“错误7 :项目已经拥有“。 买的物品就像我的应用程序的亲版本。

问题: 我在哪里以及如何处理已经购买的物品?

嗨,你显示在应用程序购买屏幕之前,你应该检查你是否已经订购了非消耗品之前。

好文章阅读:

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); 
} 
} 
};