C++ Library

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.

NDK Modules

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

Cocos2dx

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:

Static Library Module

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);
     ...
 }

Shared Library Module

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");
  }

C++ API

Use the TapjoyCpp.h header file:


 #include "Tapjoy/TapjoyCpp.h" // Tapjoy C++ API

using namespace tapjoy;

  Tapjoy::trackEvent("some event");

Push Opt out C++ API for Android SDK 11.1+

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.

Privacy

Full details here.

API

TJPrivacyPolicyHandle policyHandle;
policyHandle = TJPrivacyPolicy::getPrivacyPolicy();
TJPrivacyPolicy::subjectToGDPR(policyHandle,true);
TJPrivacyPolicy::setUserConsent(policyHandle, "1″);
TJPrivacyPolicy::setUSPrivacy(policyHandle, "1YNY");
TJPrivacyPolicy::belowConsentAge(policyHandle, true);

Referrer

Integrate Tapjoy's InstallReferrerClient with Tapjoy Analytics

  1. Add com.android.installreferrer:installreferrer in your <app_level> build.gradle.
  2. If you are using coco engine in your TapjoyIntegration.cpp, create the native method to call 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
  1. Call the native method from the <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();
 }
}