title: Implementing In-App Billing with libgdx
body: <p>So this is an issue I´ve dealt with for about 2 months now and I really need some assistance with this one. Im doing an app and I want the user to be able to buy certain stuff.</p>
  
  <p>I´ve followed this guide as far as I´ve been capable: <a href="http://developer.android.com/google/play/billing/billing_integrate.html" rel="nofollow">http://developer.android.com/google/play/billing/billing_integrate.html</a></p>
  
  <p>The thing is, Im using Libgdx which makes it a bit tricky for me. I got it most of the stuff implemented in the AndroidLauncher class which is the main I suspect. Looks like this:</p>
  
  <pre><code>public class AndroidLauncher extends AndroidApplication {
  
  IInAppBillingService mservice;
  ServiceConnection connection = new ServiceConnection() {
  
      public void onServiceConnected(ComponentName name, IBinder service) {
          mservice = IInAppBillingService.Stub.asInterface(service);
  
  
      }
  
  
  
  
  
      @Override
      public void onServiceDisconnected(ComponentName name) {
  
          mservice = null;
      }
  
  
  
  
  
  };
  
  
  @Override
  protected void onCreate (Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
      initialize(new TombStone(null), config);
  
      Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
      serviceIntent.setPackage("com.android.vending");
      bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE);
  
  
      // The list the holds all the items available for purchase
      ArrayList&lt;String&gt; skuList = new ArrayList&lt;String&gt; ();
      skuList.add("premiumUpgrade");
      skuList.add("gas");
      Bundle querySkus = new Bundle();
      querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
  
      try {
          Bundle skuDetails = mservice.getSkuDetails(3, getPackageName(), "inapp", querySkus);
      } catch (RemoteException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  
  
  @Override
  protected void onDestroy() {
      // TODO Auto-generated method stub
      super.onDestroy();
      if(mservice != null) {
          unbindService(connection);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Although that class isn´t the class where the actuall "store" screen is. That is this class:</p>
  
  <pre><code>public class Stones implements Screen {
  
  
  OrthographicCamera camera;
  final TombStone game;
  
  
  private Stage stage;
  private TextureAtlas atlas;
  private Skin skin;
  private Table table;
  private BitmapFont font;
  ImageButton btnArrow, btnArrowLeft, imageButton1, imageButton2, imageButton3, imageButton4, imageButton5, imageButton6;
  
  
  public  Texture background, testImage, arrow, arrowLeft;
  public  TextureAtlas buttonAtlas;
  
  public Stones(TombStone gam)    {
      game = gam;
  
      game.assets.load();
      loadStore();
      camera = new OrthographicCamera();
      camera.setToOrtho(false, 136, 204);
  
  
  
  }
  
  public void loadStore()  {
      background = game.assets.storeBackground;
      testImage = game.assets.image;
      arrow = game.assets.arrow;
      arrowLeft = game.assets.arrowLeft;
  }
  
  @Override
  public void render(float delta) {
  
      camera.update();
      game.batch.setProjectionMatrix(camera.combined);
  
  
      game.batch.begin();
  
      game.batch.draw(background, 0, 0, 136, 204);
      game.font.setScale(0.5f);
      game.font.draw(game.batch, "This is the current selection of tombstones! Simply click the image of the stone you want to buy it.", 50, 200);
  
      game.batch.end();
  
      //Draws the ImageButtons
      stage.act();
      stage.draw();
  
  }
  
  @Override
  public void resize(int width, int height) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void show() {
  
      Skin skin = new Skin();
  
  
  
      //ArrowButtons
      Skin skinTwo = new Skin();
      buttonAtlas = new TextureAtlas(Gdx.files.internal("arrow.pack"));
      skinTwo.addRegions(buttonAtlas);
      ImageButtonStyle styleTwo = new ImageButtonStyle();
      TextureRegionDrawable arrowImage = new TextureRegionDrawable(new TextureRegion(new Texture("arrowLeft.png")));
      styleTwo.up = skinTwo.newDrawable(skinTwo.newDrawable(arrowImage));
      styleTwo.down = skinTwo.newDrawable(skinTwo.newDrawable(arrowImage));
  
  
  
      //ImageButtons - Category buttons
      ImageButtonStyle style = new ImageButtonStyle();
      TextureRegionDrawable ibimage = new TextureRegionDrawable(new TextureRegion(new Texture("image.png")));
  
      style.up = skin.newDrawable(skin.newDrawable(ibimage));
      style.down = skin.newDrawable(skin.newDrawable(ibimage));
      imageButton1 = new ImageButton(style);
      imageButton2 = new ImageButton(style);
      imageButton3 = new ImageButton(style);
      imageButton4 = new ImageButton(style);
      imageButton5 = new ImageButton(style);
      imageButton6 = new ImageButton(style);
  
      //ArrowButtons implement
      btnArrow = new ImageButton(styleTwo);
  
      btnArrow.setSize(150, 150);
      btnArrow.setPosition(450, 10);
  
  
      /*table = new Table();
      table.setBounds(100, 100, 100, 100);
  
      skin = new Skin();
      font = new BitmapFont();
  
      TextureRegion image = new TextureRegion(testImage);
      stage = new Stage();
      Gdx.input.setInputProcessor(stage);
  
      //ImageButtonStyle style = new ImageButtonStyle(skin.get(ButtonStyle.class));
      //style.imageUp = new TextureRegionDrawable(image);
      //style.imageDown = new TextureRegionDrawable(image);
      ImageButton iconButton = new ImageButton(skin);
  
      //Button imgButton = new Button(new Image(image), skin);*/
  
  
  
      //Stage for the BuyImages
      stage = new Stage();
  
  
  
      table = new Table();
      table.setBounds(20, 320, 175, 1050);
  
      table.add(imageButton1).pad(5).size(175, 175).row();
      table.add(imageButton2).pad(5).size(175, 175).row();
      table.add(imageButton3).pad(5).size(175, 175).row();
      table.add(imageButton4).pad(5).size(175, 175).row();
      table.add(imageButton5).pad(5).size(175, 175).row();
      table.add(imageButton6).pad(5).size(175, 175).row();
  
  
  
      stage.addActor(table);
      stage.addActor(btnArrow);
  
      Gdx.input.setInputProcessor(stage);
  
  
      //Backbutton
      btnArrow.addListener(new ChangeListener() {
  
          @Override
          public void changed(ChangeEvent event, Actor actor) {
              game.setScreen(new StoreScreen(game));
  
          }
  
  
      });
  
      imageButton1.addListener(new ChangeListener() {
  
          @Override
          public void changed(ChangeEvent event, Actor actor) {
  
  
          }
  
  
      });
  
  }
  
  @Override
  public void hide() {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void pause() {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void resume() {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void dispose() {
      // TODO Auto-generated method stub
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So I suspect that I´ll need to link the first class to the second somehow to be able to use the stuff I´ve implemented in the first one? But how? And after that Im sort of lost. 
  I´ve looked at a bunch of tutorials but none describes my problem more specificly.
  Help would be tremendous!
  Thanks in advance</p>