Search code examples
androidin-app-billing

In App billing not showing popup message after BillingProcessor.purchase


I'm still new to in-app billing in Android. I've tried exactly the same with this tutorial but never get the pop up. Here's the link

GitHub

Tutorial Video

Here's my code

MainActivity

public class MainActivity extends AppCompatActivity implements BillingProcessor.IBillingHandler {
    BillingProcessor bp;
    Button purchase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        bp = new BillingProcessor(this, null, this);
        purchase = (Button) findViewById(R.id.purchase);

        purchase.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bp.purchase(MainActivity.this, "android.test.purchased");
            }
        });

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                bp.purchase(MainActivity.this, "android.test.purchased");
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {
        showToast("You Have Purchased The Product");
    }

    @Override
    public void onPurchaseHistoryRestored() {

    }

    @Override
    public void onBillingError(int errorCode, @Nullable Throwable error) {
        showToast("An Error Has Occurred");
    }

    @Override
    public void onBillingInitialized() {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        if(!bp.handleActivityResult(requestCode, resultCode, data)){
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

    @Override
    public void onDestroy(){
        if(bp != null){
            bp.release();
        }
        super.onDestroy();
    }

    private void showToast(String message) {
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}

I've added this in build.gradle APP

compile 'com.anjlab.android.iab.v3:library:1.0.+'

And in AndroidManifest, I've added billing permission too

<uses-permission android:name="com.android.vending.BILLING" />

I'm really stuck even i tried to do it exactly the same as the tutorial. Could you please help out where is the problem.


Solution

  • Licence key AND product Id CANNOT be null anymore in the latest version of google pay. You must create an alpha release with your product ID and Developer Licence key as the way they're in the console.

    Also, you must wait about 30 minutes after you publish your alpha release to test your billing.

    Hope that helps!!

    (Make sure you've added INTERNET permission; Replace the "+" sign in your build.gradle with the version you'll find on the change log)