Hallo,
ich scheitere daran, In-App-Käufe in meine App zu implementieren.
Ich möchte, dass wenn ein Button geklickt wird, dass dann der In-App-Kauf "noads" getätigt wird.
Ich habe den In-App-Kauf bereits in der Google Developer-Console erstellt. Er heißt "noads".
Ich habe auch die Klasse IaHelper importiert mit der "IInAppBillingService.aidl" Datei.
Was ich jetzt machen soll, ist mir nur unzureichend klar.
Ich habe folgenden Code:
Code
package de.ubik.terminkalender;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class NoadsActivity extends AppCompatActivity {
private int count;
private IabHelper mHelper;
private boolean isFullVersion;
boolean mIsPremium = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_noads);
String base64EncodedPublicKey = "blabla";// CONSTRUCT_YOUR_KEY_AND_PLACE_IT_HERE
mHelper = new IabHelper(this, base64EncodedPublicKey);
// enable debug logging (for a production application, you should set this to false).
mHelper.enableDebugLogging(true);
final IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isFailure()) {
return;
}
else if (purchase.getSku().equals("noads")) {
// Deaktiviere Ads
}
}
};
// Start setup. This is asynchronous and the specified listener
// will be called once setup completes.
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
return;
}
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// IAB is fully set up. Now, let's get an inventory of stuff we own.
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
try {
mHelper.launchPurchaseFlow(NoadsActivity.this, "noads", 10001,
mPurchaseFinishedListener, );
} catch (IabHelper.IabAsyncInProgressException e) {
}
} catch (IabHelper.IabAsyncInProgressException e) {
}
}
});
}
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) return;
// Is it a failure?
if (result.isFailure()) {
return;
}
/*
* Check for items we own. Notice that for each purchase, we check
* the developer payload to see if it's correct! See
* verifyDeveloperPayload().
*/
// Do we have the premium upgrade?
Purchase premiumPurchase = inventory.getPurchase("noads");
mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase));
}
};
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;
}
}
Alles anzeigen
Wenn ich die Activity aufrufe, passiert nichts.
Auf der Console wird das hier ausgeben:
Code
11-26 16:54:57.387 32473-32473/de.ubik.terminkalender D/IabHelper: Starting in-app billing setup.
11-26 16:54:57.443 32473-32473/de.ubik.terminkalender D/IabHelper: Billing service connected.
11-26 16:54:57.443 32473-32473/de.ubik.terminkalender D/IabHelper: Checking for in-app billing 3 support.
11-26 16:54:57.450 32473-32473/de.ubik.terminkalender D/IabHelper: In-app billing version 3 supported for de.ubik.terminkalender
11-26 16:54:57.456 32473-32473/de.ubik.terminkalender D/IabHelper: Subscription re-signup AVAILABLE.
11-26 16:54:57.456 32473-32473/de.ubik.terminkalender D/IabHelper: Starting async operation: refresh inventory
11-26 16:54:57.460 32473-4495/de.ubik.terminkalender D/IabHelper: Querying owned items, item type: inapp
11-26 16:54:57.460 32473-4495/de.ubik.terminkalender D/IabHelper: Package name: de.ubik.terminkalender
11-26 16:54:57.460 32473-4495/de.ubik.terminkalender D/IabHelper: Calling getPurchases with continuation token: null
11-26 16:54:57.467 32473-4495/de.ubik.terminkalender D/IabHelper: Owned items response: 0
11-26 16:54:57.467 32473-4495/de.ubik.terminkalender D/IabHelper: Continuation token: null
11-26 16:54:57.467 32473-4495/de.ubik.terminkalender D/IabHelper: Querying owned items, item type: subs
11-26 16:54:57.467 32473-4495/de.ubik.terminkalender D/IabHelper: Package name: de.ubik.terminkalender
11-26 16:54:57.467 32473-4495/de.ubik.terminkalender D/IabHelper: Calling getPurchases with continuation token: null
11-26 16:54:57.475 32473-4495/de.ubik.terminkalender D/IabHelper: Owned items response: 0
11-26 16:54:57.475 32473-4495/de.ubik.terminkalender D/IabHelper: Continuation token: null
11-26 16:54:57.475 32473-4495/de.ubik.terminkalender D/IabHelper: Ending async operation: refresh inventory
Alles anzeigen