美好的一天。我正在实施应用内购买到android。只有硬币的项目是硬币。并且想法硬币可以一遍又一遍地购买。但是我们知道谷歌播放应用内购买保持购买的商品,你只能在消费后购买。所以这种情况的最佳做法是什么?我希望让用户一遍又一遍地购买相同的硬币包。它的代码是什么? 这是我用于应用内购买流程的代码。
<input type="radio" id="tiMs" name="ti" value="Ms" tabindex="16" class="invalid">
<input type="radio" id="tiMiss" name="ti" value="Miss" tabindex="17" class="invalid">
<input type="radio" id="tiMiss" name="hol" value="Miss" tabindex="17" class="invalid">
<a href="#" id="submiter">
<strong>clickit</strong>
</a>
我注意到这个问题,因为在第一次购买时一切都很顺利,每当我再次尝试购买相同的sku命名项目时,我会得到这样的致命异常
private ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
try {
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
Log.d("Fasfsafasfasfa", "onServiceConnected: "+ownedItems);
int response = ownedItems.getInt("RESPONSE_CODE");
Log.d("Fasfsafasfasfa", "onServiceConnected: "+response);
if (response == 0) {
ArrayList<String> ownedSkus =
ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList =
ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList =
ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
String continuationToken =
ownedItems.getString("INAPP_CONTINUATION_TOKEN");
Log.d("Fasfsafasfasfa", "onServiceConnected: "+ownedSkus.size());
Log.d("Fasfsafasfasfa", "onServiceConnected: "+purchaseDataList.size());
Log.d("Fasfsafasfasfa", "onServiceConnected: "+signatureList.size());
Log.d("Fasfsafasfasfa", "onServiceConnected: "+continuationToken);
for (int i = 0; i < purchaseDataList.size(); ++i) {
String purchaseData = purchaseDataList.get(i);
String signature = signatureList.get(i);
String sku = ownedSkus.get(i);
// do something with this purchase information
// e.g. display the updated list of products owned by user
Log.d("Fasfsafasfasfa", "onServiceConnected: " + "purchased items are" + sku + " " + signature + " " + purchaseData);
}
// if continuationToken != null, call getPurchases again
// and pass in the token to retrieve more items
}
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
"small_pack", "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(),
1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
} catch (RemoteException e) {
e.printStackTrace();
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
};
我可以认为这意味着我必须首先消费购买,然后再次让用户购买它。我是对的?无论如何谁有这个问题的建议?
答案 0 :(得分:1)
使用您的商品使其可以再次购买:
int response = mService.consumePurchase(3, getPackageName(), token);
警告:不要在主线程上调用consumePurchase方法。调用此方法会触发可能阻止主线程的网络请求。相反,创建一个单独的线程并从该线程内部调用consumePurchase方法。
消费品可由用户多次购买。
非消耗品只能购买一次。