In app billing no ui

Viewed 79

i'm looking to study in App Billing. i have created a test app. I can see my in app product insered into Play Console, with getSkuDetails, but when i start launchPurchaseFlow, the interface to buy in app product not start, and i can see only the log(Log its ok)

public class MainActivity extends Activity implements View.OnClickListener {

    Button compra,click,controllo;
    private IabHelper.QueryInventoryFinishedListener mQueryFinishedListener;

    IInAppBillingService mService;

    ServiceConnection mServiceConn = new ServiceConnection() {
        @Override
        public void onServiceDisconnected(ComponentName name) {
            mService = null;
        }

        @Override
        public void onServiceConnected(ComponentName name,
                                       IBinder service) {
            mService = IInAppBillingService.Stub.asInterface(service);
        }
    };

    private static final String TAG="INappBILLING";
    IabHelper mHelper;


    static final String ITEM_SKU="dsada";
    public monky.myapplication.util.IabHelper.OnIabPurchaseFinishedListener 
    mPurchaseFinishedListener;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent serviceIntent =
                new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

        compra=(Button) findViewById(R.id.buybtn);
        compra.setOnClickListener(this);
        click=(Button)findViewById(R.id.clickbtn);
        click.setOnClickListener(this);
        controllo=(Button) findViewById(R.id.controllo);
        controllo.setOnClickListener(this);



        String base64EncodedPublicKey="mykey";

        mHelper=new IabHelper(this,base64EncodedPublicKey);

        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);
                }
                // Hooray, IAB is fully set up!
            }
        });



        }





    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mService != null) {
            unbindService(mServiceConn);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){

            case R.id.clickbtn:

                List additionalSkuList = new ArrayList();
                additionalSkuList.add(ITEM_SKU);
                mHelper.queryInventoryAsync(true, additionalSkuList,
                        mQueryFinishedListener);


                mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
                    public void onQueryInventoryFinished(IabResult result, Inventory inventory)
                    {
                        if (result.isFailure()) {
                            Log.i(TAG, " - Prezzo  Error" );
                            return;
                        }


                        String prezzo = inventory.getSkuDetails(ITEM_SKU).getPrice();

                        String titolo = inventory.getSkuDetails(ITEM_SKU).getTitle();

                        String desc = inventory.getSkuDetails(ITEM_SKU).getDescription();

                        String type = inventory.getSkuDetails(ITEM_SKU).getType();

                        String SkU = inventory.getSkuDetails(ITEM_SKU).getSku();

                        Toast.makeText(getApplicationContext(),"Titolo: "+titolo+" Desc "+desc+" Prezzo "+prezzo+" Tipo "+type+"SKU"+SkU  ,Toast.LENGTH_LONG).show();
                        Log.i(TAG, " - Prezzo " + prezzo);

                        // update the UI
                    }
                };

                break;

            case R.id.buybtn:
                if (!mHelper.isAsyncInProgress()){

                    mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001,
                            mPurchaseFinishedListener,"" );
                    Log.i(TAG, "  sono passato " );}
                else {
                    Log.i(TAG, " Non sono passato " );
                }



                break;


            case R.id.controllo:
                controlloaq();
                break;

        }
    }

    private void controlloaq() {

        IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
                = new IabHelper.OnIabPurchaseFinishedListener() {
            public void onIabPurchaseFinished(IabResult result, Purchase purchase)
            {
                if (purchase.getSku().equals(ITEM_SKU)) {
                    Log.i(TAG, "   passato  e comprato" );
                }

                if (result.isFailure()) {
                    Log.i(TAG, "Error purchasing: " + result);
                    return;
                }



            }
        };
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Log.d(TAG, "onActivityResult(" + requestCode + "," + resultCode + ","
                + data);

        // Pass on the activity result to the helper for handling
        if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
            super.onActivityResult(requestCode, resultCode, data);
        } else {
            Log.d(TAG, "onActivityResult handled by IABUtil.");
        }
    }
}
1 Answers
Related