Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface purchasesInterface() {
- public void purchaseItem();
- }
- ________________
- AndroidLauncher:
- public class AndroidLauncher extends AndroidApplication implements purchaseInterface{
- @Override
- protected void onCreate (Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- initialize(new MainClass(this), config);
- mHelper = new IabHelper(this, base64EncodedPublicKey);
- mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
- public void onIabSetupFinished(IabResult result) {
- if (!result.isSuccess()) {
- // IF any problem occurs, log that.
- Log.d("IAB", "Problem setting up In-app Billing: " + result);
- }
- // IAB is success
- Log.d("IAB", "Billing Success: " + result);
- processPurchases();
- }
- });
- }
- @Override
- public void purchaseItem() {
- // TODO Auto-generated method stub
- mHelper.launchPurchaseFlow(this, ITEM_1, RC_REQUEST, mPurchaseFinishedListener, "HANDLE_PAYLOADS");
- }
- __________________
- IOSLauncher:
- public class IOSLauncher extends IOSApplication.Delegate implements purchaseInterface{
- private InAppPurchaseManager iapManager;
- private Map<String, SKProduct> appStoreProducts;
- @Override
- protected IOSApplication createApplication() {
- IOSApplicationConfiguration config = new IOSApplicationConfiguration();
- config.orientationPortrait = true;
- config.orientationLandscape = false;
- return new IOSApplication(new MainClass(this), config);
- }
- @Override
- public boolean didFinishLaunching(UIApplication application, UIApplicationLaunchOptions launchOptions) {
- super.didFinishLaunching(application, launchOptions);
- iapManager = new InAppPurchaseManager(new InAppPurchaseListener() {
- @Override
- public void productsReceived(SKProduct[] skProducts) {
- // Store the products.
- appStoreProducts = new HashMap<String, SKProduct>();
- for (int i = 0; i < skProducts.length; i++) {
- appStoreProducts.put(skProducts[i].getProductIdentifier().toString(), skProducts[i]);
- }
- Gdx.app.debug("productsReceived", "Total products: " + appStoreProducts.size());
- // Fill your shop UI with products here.
- }
- @Override
- public void productsRequestFailed(SKRequest skRequest, NSError nsError) {
- }
- @Override
- public void transactionCompleted(SKPaymentTransaction skPaymentTransaction) {
- // Purchase successfully completed.
- // Get the product identifier and award the product to the user.
- String productId = skPaymentTransaction.getPayment().getProductIdentifier().toString();
- Gdx.app.debug("IOSApplication transactionCompleted", "Retrieved id: " + productId);
- Gdx.app.debug("IOSApplication transactionCompleted", "Wanted id: " + IOSpurchaseInterface.TOMBSTONE_2);
- if (productId.equals(IOSpurchaseInterface.ITEM_1)) {
- item1 = true;
- }
- }
- @Override
- public void transactionFailed(SKPaymentTransaction skPaymentTransaction, NSError nsError) {
- }
- @Override
- public void transactionRestored(SKPaymentTransaction skPaymentTransaction) {
- // Purchase successfully restored.
- // Get the product identifier and award the product to the user. This is only useful for non-consumable products.
- String productId = skPaymentTransaction.getPayment().getProductIdentifier().toString();
- Gdx.app.debug("IOSApplication transactionRestored", "Retrieved id: " + productId);
- if (productId.equals(purchaseInterface.ITEM_1)) {
- item1 = true;
- }
- }
- @Override
- public void transactionRestoreFailed(NSArray<SKPaymentTransaction> nsArray, NSError nsError) {
- }
- });
- // First request the available products from the app store.
- iapManager.restoreTransactions();
- return true;
- }
- public static void main(String[] argv) {
- NSAutoreleasePool pool = new NSAutoreleasePool();
- UIApplication.main(argv, null, IOSLauncher.class);
- pool.close();
- }
- @Override
- public void purchaseItem() {
- iapManager.requestProducts(IOSpurchaseInterface.ITEM_1);
- // At any time you want to purchase a product.
- if (iapManager.canMakePayments() && appStoreProducts != null) {
- Gdx.app.debug("IOSApplication", "Buying products");
- iapManager.purchaseProduct(appStoreProducts.get(IOSpurchaseInterface.ITEM_1));
- }else{
- Gdx.app.debug("IOSApplication payments?", ""+iapManager.canMakePayments());
- //Gdx.app.debug("IOSApplication products", "" + appStoreProducts.size());
- }
- }
- _____________________
- Purchasing
- Screen Class:
- public class FlowerScreen implements Screen, purchaseInterface {
- purchaseInterface pInt;
- public FlowerScreen(MainClass gam) {
- game = gam;
- this.pInt = game.pi;
- ...
- ...
- buyBtn1.addListener(new ChangeListener() {
- @Override
- public void changed(ChangeEvent event, Actor actor) {
- purchaseItem();
- }
- });
- @Override
- public void purchaseItem() {
- pInt.purchaseItem();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement