Tapjoy provides a C++ API on development environments that use Android NDK and C++, such as Cocos2d-x.
The C++ API which is provided by Tapjoy’s Android SDK is compatible with Tapjoy’s iOS SDK’s C++ API.
An NDK module which offers C++ header file and library is included in Tapjoy SDK. Please add Tapjoy’s NDK Modules’ path as NDK_MODULE_PATH.
ndk-build NDK_MODULE_PATH=../../TapjoySDK_Android/Library/modules
Add NDK_MODULE_PATH
separated by colon(:) to proj.android/build_native.sh
:
# proj.android/build_native.sh
...
if [[ "$buildexternalsfromsource" ]]; then
echo "Building external dependencies from source"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source:../../TapjoySDK_Android/Library/modules"
else
echo "Using prebuilt externals"
"$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt:../../TapjoySDK_Android/Library/modules"
fi
Use one of the following modules:
Link your application library to the Static Library Module.
Add fiverocks_static module:
From the app project, add the tapjoy_static module to Android.mk file that builds Tapjoy API integration source code.
```make
...
include $(CLEAR_VARS)
...
LOCAL_STATIC_LIBRARIES := tapjoy_static
...
include $(BUILD_SHARED_LIBRARY)
...
$(call import-module,tapjoy)
...
Provide JavaVM:
`tapjoy_static` module requires a JavaVM object. Find the function definition of `JNI_OnLoad` and add the `Tapjoy::setJavaVM` method:
```java
#include "TapjoyCpp.h" // Tapjoy C++ API
...
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
...
JniHelper::setJavaVM(vm);
tapjoy::Tapjoy::setJavaVM(vm);
...
}
You can also use the Shared Library Module. This does not require JavaVM.
Add the tapjoy_shared
module:
From the app project, add the tapjoy_shared
module to Android.mk file that builds Tapjoy API integration source code:
```make
...
include $(CLEAR_VARS)
...
LOCAL_SHARED_LIBRARIES := tapjoy_shared
...
include $(BUILD_SHARED_LIBRARY)
...
$(call import-module,tapjoy)
...
Resolve Shared Library Module’s dependency issue:
Before loading the application library that uses Tapjoy Library, call `Tapjoy.loadSharedLibrary()`:
```java
import com.tapjoy.Tapjoy;
static {
Tapjoy.loadSharedLibrary();
System.loadLibrary("YourAppLibrary");
}
Use the TapjoyCpp.h
header file:
#include "Tapjoy/TapjoyCpp.h" // Tapjoy C++ API
using namespace tapjoy;
Tapjoy::trackEvent("some event");
You can opt out users who don’t want to receive push notifications by using this API. You should connect to Tapjoy SDK first by using Tapjoy.connect call before use this.
// To get the current status
bool Tapjoy::isPushNotificationDisabled()
// To set/unset push notification disabled
void Tapjoy::setPushNotificationDisabled(bool)
We recommend you to add a toggle or checkbox UI to your app’s setting page.
Full details here.
TJPrivacyPolicyHandle policyHandle;
policyHandle = TJPrivacyPolicy::getPrivacyPolicy();
TJPrivacyPolicy::subjectToGDPR(policyHandle,true);
TJPrivacyPolicy::setUserConsent(policyHandle, "1″);
TJPrivacyPolicy::setUSPrivacy(policyHandle, "1YNY");
TJPrivacyPolicy::belowConsentAge(policyHandle, true);
com.android.installreferrer:installreferrer
in your <app_level> build.gradle.Tapjoy::activateInstallReferrerClient(contex);
. See the sample implementation below:#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
extern "C" void Java_org_cocos2dx_cpp_AppActivity_activateInstallReferrerClient(JNIEnv* jenv,jobject thiz) {
static jobject context = jenv->NewGlobalRef(thiz);
Tapjoy::activateInstallReferrerClient(context);
}
#endif
<your_app_main_activity>.java
. See the sample implementation below:public class AppActivity extends Cocos2dxActivity {
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setActivity();
activateInstallReferrerClient();
Tapjoy.setDebugEnabled(true);
}
public native void setActivity();
public native void activateInstallReferrerClient();
static {
Tapjoy.loadSharedLibrary();
}
}