Anyone got in-app purchasing for Android working?

Could anyone give me a pointer for how you’d do the code for in-app purchasing in an Android SDL game? Does it need to be in Java, or can you do it in C++? Has anybody got this to work, and would be willing to share their code and know-how?

You need write code on Java and some wrappers on C/C++. C/C++ interacts with Java and vice verca through JNI.
May be my example is not the best choise but it can point you to the right direction.

billing.h
billing.cpp
BillingManager.java

Do not forget add into yor gradle build file.
implementation 'com.android.billingclient:billing:3.0.0'

BillingManager pushes events to your application and your app should handle it.

This code implemented on this android app published on Google Play.

1 Like

Wow, thanks for your help, that’s much appreciated and I’ll have a go at using your code in my apps!

I’m having a few problems integrating your code and I’d be really grateful if you could give me some pointers! I couldn’t find these files that were #included:

#include “basewrapper.h”
#include “core/platformwrapper/android/android_billing.h”

Also, I wasn’t sure where the BillingManager.java file should be moved to? Should it go in the same folder as the file MyGame.java file, or I guess to the folder with the SDL .java files?

My SDK root is here: framework. And there is basewrapper.h and others. And core folder too.
In my case BillingManager.java located in here but you should specify path in your build.gradle.file. Something like that

def akkord_sdk_path        = System.getenv('AKKORD_SDK_HOME')
...
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
            manifest.srcFile '../AndroidManifest.xml'
            java.srcDir "${akkord_sdk_path}/libraries/SDL/SDL/android-project/app/src/main/java/org/libsdl/app/"
            java.srcDir "${akkord_sdk_path}/framework/core/platformwrapper/android/wrapper/"
            java.srcDir "${akkord_sdk_path}/framework/core/platformwrapper/android/admob/"
            java.srcDir "${akkord_sdk_path}/framework/core/platformwrapper/android/billing/"
            java.srcDir '../java'
            res.srcDirs = ['../res']
            assets.srcDir '../../assets'
        }
    }

My full build.gradle file is here.

Hello can you read this problem? : Android project stop responding when go background during in app purchase.