我正在尝试使用应用内购买,在我想购买我的商品后,我在“IabHelper.OnConsumeFinishedListener mConsumeFinishedListener”的结果中收到以下错误 我的物品不是订阅!
result.getmessage如下:“'subs'类型的项目不能被消费。(响应:-1010:消费尝试无效)”
我该怎么办?
我的完整代码:
公共类BuyCoins扩展活动{
String TAG="TESTPURCHASE";
IabHelper mHelper;
static final String ITEM_100_SKU = "ir.e_rundev.brainwars.test";
static final String ITEM_500_SKU = "ir.e_rundev.brainwars.test2";
static final String ITEM_1000_SKU = "ir.e_rundev.brainwars.1000coins";
String ITEM_SKU="";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.buy_coins);
Swarm.setActive(this);
String base64EncodedPublicKey =
"(I HAVE MY CODE HERE)";
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new
IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess()) {
// Log.d(TAG, "In-app Billing setup failed: " +
// result);
} else {
// Log.d(TAG, "In-app Billing is set up OK");
}
}
});
Button btn100 = (Button) findViewById(R.id.btn_Buy_100);
Button btn500 = (Button) findViewById(R.id.btn_Buy_500);
Button btn1000 = (Button) findViewById(R.id.btn_Buy_1000);
btn100.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ITEM_SKU=ITEM_100_SKU;
buyCoin(view);
}
});
btn500.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ITEM_SKU=ITEM_500_SKU;
buyCoin(view);
}
});
btn1000.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// ITEM_SKU=ITEM_1000_SKU;
// buyCoin(view);
}
});
}
public void buyCoin (View view) {
mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001,
mPurchaseFinishedListener, "mypurchasetoken");
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
if (!mHelper.handleActivityResult(requestCode,
resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
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_100_SKU)) {
consumeItem();
Log.d(TAG, "Here"+purchase.getItemType());
} else if (purchase.getSku().equals(ITEM_500_SKU)) {
consumeItem();
} else if (purchase.getSku().equals(ITEM_1000_SKU)) {
consumeItem();
}
}
public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
Log.d(TAG,"here 3");
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// Handle failure
} else {
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
mConsumeFinishedListener);
Log.d(TAG,"here 4"+inventory.getPurchase(ITEM_SKU).getItemType());
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
if (result.isSuccess()) {
//clickButton.setEnabled(true);
// Log.d(TAG,"SUCCESSFUL");
purchaseFinished(ITEM_SKU);
Log.d(TAG,"here2");
SharedPreferences settings = getSharedPreferences("MYSETTINGS", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("isPremium", true);
editor.apply();
Adad.setDisabled(true);
} else {
// handle error
Log.d(TAG,"here 5");
Log.d(TAG,result.getMessage());
Log.d(TAG,purchase.toString());
}
}
};
};
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) {
mHelper.dispose();
mHelper = null;
}
}
public void onResume() {
super.onResume();
Swarm.setActive(this);
TextView tvCoins = (TextView) findViewById(R.id.tv_Buy_Coins);
GameInventory gameInventory = new GameInventory(getApplicationContext());
tvCoins.setText(String.valueOf(gameInventory.getCoinsCount()));
}
public void onPause() {
super.onPause();
Swarm.setInactive(this);
}
private void purchaseFinished(String SKU){
GameInventory gameInventory = new GameInventory(getApplicationContext());
if (SKU==ITEM_100_SKU) {
gameInventory.updateCoinsCount(gameInventory.getCoinsCount() + 100);
}else if(SKU==ITEM_500_SKU){
gameInventory.updateCoinsCount(gameInventory.getCoinsCount() + 520);
}else if (SKU==ITEM_1000_SKU){
gameInventory.updateCoinsCount(gameInventory.getCoinsCount() + 1100);
}
ITEM_SKU = "";
}
}
答案 0 :(得分:2)
嘿我从10天开始就开始从事InApp购买工作,并且我已成功整合到我现有的应用程序中,并准备好将其投入使用。最初,当我开始这样做时,我已经下载了谷歌InApp计费示例,名为" Trivial Drive"来自here。
但它并没有给我很多帮助,因为它有很多问题和错误,所以我决定自己从头开始使用新的v3 api,你可以找到here。本教程有明确的解释,可以帮助您,如果您有时间,请参阅this YouTube视频,Google员工已明确说明如何集成它。
另外,如果您想要快速举例,我可以从here下载示例应用。
以下视频还介绍了如何集成InApp Purchase。请仔细阅读。
https://www.youtube.com/watch?v=-h2ESH71hAI
谢谢