Hi,
Also ich versuche gerade In-App Billing V3 zu implementieren und habe es auch geschafft ein einmaligen kauf durchzuführen ---> (Test App) App öffnet sich Google Play "kauf Fenster" öffnet sich --> erfolgreicher kauf. Ich will aber dass die user unendlich viele coins kaufen können. Ich hab jetzt auch den code angepasst mit mHelper.consumeAsync(inventory.getPurchase("coins"), mConsumeFinishedListener); damit es wieder erhältlich ist (ist in allen tutorials so gemacht) aber an der App ändert sich nichts !!
Hier mal mein code (manche Kommentare sind noch aus TrivalDriver aus dem ich das meiste kopiert hab :
Code
public class MainActivity extends AppCompatActivity {
IabHelper mHelper;
boolean verifyDeveloperPayload(Purchase p) {
String payload = p.getDeveloperPayload();
/*
* TODO: verify that the developer payload of the purchase is correct. It will be
* the same one that you sent when initiating the purchase.
*
* WARNING: Locally generating a random string when starting a purchase and
* verifying it here might seem like a good approach, but this will fail in the
* case where the user purchases an item on one device and then uses your app on
* a different device, because on the other device you will not have access to the
* random string you originally generated.
*
* So a good developer payload has these characteristics:
*
* 1. If two different users purchase an item, the payload is different between them,
* so that one user's purchase can't be replayed to another user.
*
* 2. The payload must be such that you can verify it even when the app wasn't the
* one who initiated the purchase flow (so that items purchased by the user on
* one device work on other devices owned by the user).
*
* Using your own server to store and verify developer payloads across app
* installations is recommended.
*/
return true;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String base64EncodedPublicKey = "MY_KEY";
// compute your public key and store it in base64EncodedPublicKey
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh no, there was a problem.
Log.d("TAG", "Problem setting up In-app Billing: " + result);
Log.i("TAG", "ERROR");
}
// Hooray, IAB is fully set up!
//check owned items & consum em
checkOwnedItems();
//make a test purchase
makePurchase();
}
});
}
private void makePurchase() {
try {
mHelper.launchPurchaseFlow(this, "coins", 10001, mPurchaseFinishedListener, "kp");
} catch (IabHelper.IabAsyncInProgressException e) {
e.printStackTrace();
}
}
private void checkOwnedItems() {
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
//complain("Error querying inventory. Another async operation in progress.");
}
}
// Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Purchase item = inventory.getPurchase("coins");
if (item != null && verifyDeveloperPayload(item)) {
//Log.d("TAG", "We have gas. Consuming it.");
try {
mHelper.consumeAsync(inventory.getPurchase("coins"), mConsumeFinishedListener);
} catch (IabHelper.IabAsyncInProgressException e) {
// complain("Error consuming gas. Another async operation in progress.");
}
return;
}
}
};
// Called when consumption is complete
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
Log.d("TAG", "Consumption finished. Purchase: " + purchase + ", result: " + result);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
// We know this is the "gas" sku because it's the only one we consume,
// so we don't check which sku was consumed. If you have more than one
// sku, you probably should check...
if (result.isSuccess()) {
// successfully consumed, so we apply the effects of the item in our
// game world's logic, which in our case means filling the gas tank a bit
//Log.d(TAG, "Consumption successful. Provisioning.");
//mTank = mTank == TANK_MAX ? TANK_MAX : mTank + 1;
// saveData();
// alert("You filled 1/4 tank. Your tank is now " + String.valueOf(mTank) + "/4 full!");
}
else {
//complain("Error while consuming: " + result);
}
Log.d("TAG", "End consumption flow.");
}
};
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
Log.d("TAG", "Purchase finished: " + result + ", purchase: " + purchase);
// if we were disposed of in the meantime, quit.
if (mHelper == null) return;
if (result.isFailure()) {
// complain("Error purchasing: " + result);
return;
}
if (!verifyDeveloperPayload(purchase)) {
// complain("Error purchasing. Authenticity verification failed.");
return;
}
Log.d("TAG", "Purchase successful.");
if (purchase.getSku().equals("coins")) {
Log.d("TAG", "Purchase is gas. Starting gas consumption.");
try {
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
} catch (IabHelper.IabAsyncInProgressException e) {
//complain("Error consuming gas. Another async operation in progress.");
return;
}
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) try {
mHelper.dispose();
} catch (IabHelper.IabAsyncInProgressException e) {
e.printStackTrace();
}
mHelper = null;
}
}
Alles anzeigen
Danke für Antworten