简体   繁体   中英

Intent is hijacking in app billing

I was able to implement an in app billing processor, and it tests fine without my intent to go to a new activity.
However, after a customer pays for the paid content I want a new intent to be run automatically whereby a new activity is launched (the activity with the paid content). However, when I do this the intent overtakes the billing processor, and switches to the paid activity without any billing or payment. I understand how to use a button with an intent to launch the new activity. However, another button won't work because this too would be an easy way to go around the in app billing.

Any suggestions to get around this sticky wicket? Thanks much. Yes, this is my first android app. I'm sure you can tell…

  BillingProcessor bp;

    @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);


        Button button2 = (Button) findViewById(R.id.button2);

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

//THE PROBLEM IS WHAT FOLLOWS: It overtakes .bp

                startActivity(new Intent(MainActivity.this, paidstuff.class));

           }
        });
    }

    @Override
    public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {
        Toast.makeText(this, "You just bought something great!", Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onPurchaseHistoryRestored() {

    }

    @Override
    public void onBillingError(int errorCode, @Nullable Throwable error) {

    }

    @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();
    }

}

cant you just put

startActivity(new Intent(MainActivity.this, paidstuff.class));

inside

  @Override
    public void onProductPurchased(@NonNull String productId, @Nullable TransactionDetails details) {
        Toast.makeText(this, "You just bought something great!", Toast.LENGTH_SHORT).show();

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM