0

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • SO... what is your problem/error? If you have an error, show us the log. If you have problem in understanding something, state it out. – Angus Sep 05 '18 at 10:02

1 Answers1

0

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)

Aksh
  • 321
  • 2
  • 16
  • Thanks for your answer! So, I need to create real product ID in order to test a In-App billing dummy? Can I still using the **android.test.purchased** if I create product ID? – Andhika Vnix Sep 05 '18 at 10:04
  • No you cannot (as far as I know)... Your code is perfect...you don't need to worry about your mistakes. When you're ready to publish, go for the same code...it'll work. (YOU NEED REAL KEYS) – Aksh Sep 05 '18 at 10:06
  • One more thing, when you alpha release you apk, make sure to add test email and accept invites from those. This is how google pay works now... – Aksh Sep 05 '18 at 10:10
  • Ok, I'll try to create Product ID first, then see if it works or not.. Thanks! – Andhika Vnix Sep 06 '18 at 08:29
  • I've been trying to create Alpha release and upload the APK to google console, however it always says : **You uploaded a debuggable APK or Android App Bundle. For security reasons you need to disable debugging before it can be published in Google Play** I can't find any "debug" words that can be change again. Sorry it's my first time to release an APK. – Andhika Vnix Sep 25 '18 at 09:47
  • Check your build.gradle file. Also check https://stackoverflow.com/questions/32263949/you-uploaded-a-debuggable-apk-for-security-reasons-you-need-to-disable-debuggin – Aksh Sep 25 '18 at 10:35
  • 1
    Nice! Thanks Aksh for your help. It appears your solution was spot on! – Andhika Vnix Sep 26 '18 at 07:05
  • I suggest googling the exact error msg everytime before you ask...someone already would've asked it :) saving ur time – Aksh Sep 27 '18 at 05:12