### Configure Gradle Dependencies for Tnkfactory SDK Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Adds the Tnkfactory SDK dependency and the install referrer library to the app's build.gradle file. It also configures the repositories in settings.gradle to include the Tnkfactory Maven repository. ```gradle // settings.gradle pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url "https://repository.tnkad.net:8443/repository/public/" } } } // app/build.gradle dependencies { implementation 'com.tnkfactory:rwd:8.08.40' implementation 'com.android.installreferrer:installreferrer:2.2' } ``` -------------------------------- ### Get Total Earnable Points (Kotlin & Java) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Queries the total points a user can earn from active advertisements. Supports both asynchronous (coroutines/callbacks) and synchronous methods. Requires the TNK Offerwall SDK. Returns the total points as a long. ```kotlin import com.tnkfactory.ad.TnkOfferwall import androidx.lifecycle.lifecycleScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch // Method 1: Coroutine lifecycleScope.launch(Dispatchers.IO) { val point = tnkOfferwall.getEarnPoint() runOnUiThread { tvPoint.text = point.toString() } } // Method 2: Callback tnkOfferwall.getEarnPoint { point -> tvPoint.text = point.toString() } ``` ```java import com.tnkfactory.ad.TnkOfferwall; public void showEarnPoint() { new Thread(() -> { long point = tnkOfferwall.getEarnPointSync(); runOnUiThread(() -> { tvPoint.setText("Available: " + point); }); }).start(); } ``` -------------------------------- ### Configure Android Manifest for Tnkfactory SDK Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Sets up the AndroidManifest.xml file with required permissions such as INTERNET, ACCESS_WIFI_STATE, AD_ID, and BIND_GET_INSTALL_REFERRER_SERVICE. It also includes necessary meta-data for the Tnkfactory SDK, including the app ID and tracking enablement, and declares the Offerwall Activity. ```xml ``` -------------------------------- ### Initialize and Configure Tnkfactory SDK (Kotlin) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Initializes the Tnkfactory SDK, configures user identification using the Advertising ID, sets COPPA compliance, and retrieves available reward points asynchronously. It requires lifecycleScope for coroutine dispatchers and the TnkOfferwall, AdvertisingIdInfo classes. ```kotlin import com.tnkfactory.ad.TnkOfferwall import com.tnkfactory.ad.rwd.AdvertisingIdInfo import androidx.lifecycle.lifecycleScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class MainActivity : AppCompatActivity() { lateinit var offerwall: TnkOfferwall override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Initialize SDK offerwall = TnkOfferwall(this) // Configure user identification in background thread lifecycleScope.launch(Dispatchers.IO) { val adid = AdvertisingIdInfo.requestIdInfo(this@MainActivity) // Set unique user identifier offerwall.setUserName(adid.id) // Set COPPA compliance for users under 13 offerwall.setCOPPA(false) // Query available reward points offerwall.getEarnPoint() { point -> runOnUiThread { tvPoint.text = "Available points: $point" } } } } } ``` -------------------------------- ### Display Offerwall Activity (Kotlin) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Launches the full offerwall activity to display available reward-based advertisements to users. This function is triggered by a button click and requires the TnkOfferwall class and an Activity context. ```kotlin import com.tnkfactory.ad.TnkOfferwall class MainActivity : AppCompatActivity() { lateinit var offerwall: TnkOfferwall override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) offerwall = TnkOfferwall(this) // Configure and launch offerwall btnOfferwall.setOnClickListener { offerwall.startOfferwallActivity(this@MainActivity) } } } ``` -------------------------------- ### Track User Actions for Analytics in Java Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Monitor specific user actions to analyze user behavior patterns and funnel performance. This function uses `TnkSession.actionCompleted` to log events such as resource loading, signup completion, profile entry, and friend invitations. It requires the TnkSession class from the com.tnkfactory.ad package. ```java import com.tnkfactory.ad.TnkSession; // Track resource download completion TnkSession.actionCompleted(this, "resource_loaded"); // Track user signup completion TnkSession.actionCompleted(this, "signup_completed"); // Track profile creation TnkSession.actionCompleted(this, "profile_entered"); // Track friend invitation TnkSession.actionCompleted(this, "friend_invite"); ``` -------------------------------- ### Create Placement View with Custom Layout (Kotlin) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Displays advertisements within custom placement areas using flexible UI configurations. This involves creating an AdPlacementView, configuring its event listener, and loading ads for a specific placement ID. Requires TNK Offerwall SDK and basic Android UI components. ```kotlin import com.tnkfactory.ad.TnkOfferwall import com.tnkfactory.ad.TnkAdConfig import com.tnkfactory.ad.PlacementEventListener import com.tnkfactory.ad.basic.AdPlacementView import com.tnkfactory.ad.basic.TnkAdPlacementFeedItem import com.tnkfactory.ad.basic.PlacementFeedViewLayout lateinit var adPlacementView: AdPlacementView fun setupPlacementView() { // Create placement view adPlacementView = tnkOfferwall.getAdPlacementView(this) placementContainerView.addView(adPlacementView) // Configure event listener adPlacementView.placementEventListener = object : PlacementEventListener { override fun didAdDataLoaded(placementId: String, customData: String?) { // Show ads when loaded adPlacementView.showAdList() } override fun didFailedToLoad(placementId: String) { Toast.makeText(this@MainActivity, "Ad loading failed", Toast.LENGTH_SHORT).show() } override fun didAdItemClicked(appId: String, appName: String) { Log.d("PlacementView", "Ad clicked: $appId - $appName") } override fun didMoreLinkClicked() { // Open full offerwall when user clicks "More" tnkOfferwall.startOfferwallActivity(this@MainActivity) } } } fun loadPlacementView() { // Configure layout for placement ID "open_ad" TnkAdConfig.setPlacementLayout( "open_ad", TnkAdPlacementFeedItem::class, PlacementFeedViewLayout::class ) // Load ads for placement adPlacementView.loadAdList("open_ad") } ``` -------------------------------- ### Query User Points Synchronously (Java) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Retrieves user points synchronously within a background thread, suitable for game environments where immediate point retrieval is needed without blocking the main thread. It handles potential exceptions during the query process and logs errors. ```java import com.tnkfactory.ad.TnkSession; static public void getPoint() { new Thread() { public void run() { try { int point = TnkSession.queryPoint(mActivity); showPoint(point); } catch (Exception e) { Log.e("TnkAd", "Failed to query points", e); } } }.start(); } ``` -------------------------------- ### Handle Ad Item Click Events in Kotlin Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Process individual ad click events when implementing a custom ad list UI. This code snippet defines a ViewHolder that handles click events on an ad item, initiates an ad interaction, and provides callbacks for success or failure. It requires AdPlacementView and TnkPlacementAdItem from the com.tnkfactory.ad.basic package. ```kotlin import com.tnkfactory.ad.basic.AdPlacementView import com.tnkfactory.ad.basic.TnkPlacementAdItem inner class MyAdViewHolder(val adItem: TnkPlacementAdItem) { fun onBind() { itemView.setOnClickListener { showLoading() adPlacementView.onItemClick(adItem.app_id) { success, errorMessage -> dismissLoading() if (success) { Log.d("AdClick", "Successfully opened ad: ${adItem.app_nm}") } else { showError(errorMessage) Log.e("AdClick", "Failed: $errorMessage") } } } } } ``` -------------------------------- ### Implement Server-Side Callback URL Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Process reward callbacks on your server when users earn points through ad engagement. This ensures accurate point distribution and facilitates server-to-server communication. ```APIDOC ## Implement Server-Side Callback URL ### Description Process reward callbacks on your server when users earn points through ad engagement. ### Method (HTTP POST, implementation details) ### Endpoint (Callback URL endpoint on your server) ### Parameters #### Path Parameters (None) #### Query Parameters - **pay_pnt** (integer) - Required - The points earned by the user. - **seq_id** (string) - Required - A unique identifier for the transaction. - **md_chk** (string) - Required - A security hash for verifying the request. - **md_user_nm** (string) - Required - The user identifier. #### Request Body (None) ### Request Example ```java public void handleTnkCallback(HttpServletRequest request) { // Parse callback parameters int payPoint = Integer.parseInt(request.getParameter("pay_pnt")); String seqId = request.getParameter("seq_id"); String checkCode = request.getParameter("md_chk"); String mdUserName = request.getParameter("md_user_nm"); // Your app key from Tnkfactory dashboard String appKey = "d2bbd...........19c86c8b021"; // Verify request authenticity String verifyCode = DigestUtils.md5Hex(appKey + mdUserName + seqId); if (checkCode == null || !checkCode.equals(verifyCode)) { // Invalid request log.error("tnkad() check error: " + verifyCode + " != " + checkCode); response.setStatus(500); } else { log.debug("tnkad() : " + mdUserName + ", " + seqId); // Award points to user (prevent duplicates using seqId) try { purchaseManager.awardPointsByAd(mdUserName, payPoint, seqId); response.setStatus(200); // Success } catch (DuplicateTransactionException e) { response.setStatus(200); // Already processed, return success } catch (Exception e) { log.error("Failed to award points", e); response.setStatus(500); // Will retry } } } ``` ### Response #### Success Response (200) Indicates the callback was processed successfully. #### Response Example (HTTP Status Code 200 or 500) ``` -------------------------------- ### Retrieve Placement Ad List Data in Kotlin Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Access raw advertisement data for custom UI implementation by setting up an AdPlacementView. This function retrieves ad lists and placement configurations, allowing for custom processing of ad items. It depends on the AdPlacementView, TnkPlacementAdItem, and PlacementPubInfo classes from the com.tnkfactory.ad.basic package. ```kotlin import com.tnkfactory.ad.basic.AdPlacementView import com.tnkfactory.ad.basic.TnkPlacementAdItem import com.tnkfactory.ad.basic.PlacementPubInfo lateinit var adPlacementView: AdPlacementView lateinit var adList: ArrayList lateinit var pubInfo: PlacementPubInfo fun setupPlacementView() { adPlacementView = tnkOfferwall.getAdPlacementView(this) placementContainerView.addView(adPlacementView) adPlacementView.placementEventListener = object : PlacementEventListener { override fun didAdDataLoaded(placementId: String, customData: String?) { // Get ad list adList = adPlacementView.getAdList() // Get placement configuration pubInfo = adPlacementView.getPubInfo() // Process ad items adList.forEach { adItem -> Log.d("AdData", "App: ${adItem.app_nm}, Points: ${adItem.pnt_amt}") } } override fun didFailedToLoad(placementId: String) { Toast.makeText(this@MainActivity, "Loading failed", Toast.LENGTH_SHORT).show() } override fun didAdItemClicked(appId: String, appName: String) { Log.d("AdClick", "Clicked: $appId") } override fun didMoreLinkClicked() { tnkOfferwall.startOfferwallActivity(this@MainActivity) } } } fun loadPlacementView() { adPlacementView.loadAdList("open_ad") } ``` -------------------------------- ### Purchase Item with Points (Java) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Deducts points from a user's balance when they purchase a virtual item. Requires the TNK SDK, a valid item ID, and a callback for handling success or failure. Returns remaining points and transaction ID on success, or an error indicator on failure. ```java import com.tnkfactory.ad.TnkSession; import com.tnkfactory.ad.ServiceCallback; @Override public void onClick(View v) { TnkSession.purchaseItem(MainActivity.this, 30, "item.00001", true, new ServiceCallback() { @Override public void onReturn(Context context, Object result) { long[] ret = (long[])result; if (ret[1] < 0) { // Purchase failed - insufficient points Toast.makeText(context, "Insufficient points", Toast.LENGTH_SHORT).show(); } else { // Success: ret[0] = remaining points, ret[1] = transaction ID Log.d("tnkad", "Remaining: " + ret[0] + ", Transaction: " + ret[1]); pointView.setText(String.valueOf(ret[0])); } } }); } ``` -------------------------------- ### Track Purchase Events for Analytics Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Record in-app purchase activities to measure conversion rates and ARPU metrics. Essential for understanding monetization performance. ```APIDOC ## Track Purchase Events for Analytics ### Description Record in-app purchase activities to measure conversion rates and ARPU metrics. ### Method `TnkSession.buyCompleted()` ### Endpoint (Not applicable, SDK method) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example ```java // Track item_01 purchase TnkSession.buyCompleted(this, "item_01"); // Track item_02 purchase TnkSession.buyCompleted(this, "item_02"); ``` ### Response #### Success Response (200) (Not applicable, SDK method) #### Response Example (Not applicable) ``` -------------------------------- ### Implement Server-Side Callback URL Verification in Java Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Process reward callbacks on your server when users earn points through ad engagement. This Java code verifies the authenticity of incoming callback requests using an MD5 hash of provided parameters and an app key. It handles award point logic and prevents duplicate transactions, requiring Apache Commons Codec for DigestUtils and standard Java Servlet API. ```java import org.apache.commons.codec.digest.DigestUtils; import javax.servlet.http.HttpServletRequest; // Callback URL endpoint implementation public void handleTnkCallback(HttpServletRequest request) { // Parse callback parameters int payPoint = Integer.parseInt(request.getParameter("pay_pnt")); String seqId = request.getParameter("seq_id"); String checkCode = request.getParameter("md_chk"); String mdUserName = request.getParameter("md_user_nm"); // Your app key from Tnkfactory dashboard String appKey = "d2bbd...........19c86c8b021"; // Verify request authenticity String verifyCode = DigestUtils.md5Hex(appKey + mdUserName + seqId); if (checkCode == null || !checkCode.equals(verifyCode)) { // Invalid request log.error("tnkad() check error: " + verifyCode + " != " + checkCode); response.setStatus(500); } else { log.debug("tnkad() : " + mdUserName + ", " + seqId); // Award points to user (prevent duplicates using seqId) try { purchaseManager.awardPointsByAd(mdUserName, payPoint, seqId); response.setStatus(200); // Success } catch (DuplicateTransactionException e) { response.setStatus(200); // Already processed, return success } catch (Exception e) { log.error("Failed to award points", e); response.setStatus(500); // Will retry } } } ``` -------------------------------- ### Query User Points Asynchronously (Java) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Retrieves user reward points from Tnkfactory servers asynchronously, ensuring non-blocking UI execution. This method uses the TnkSession and ServiceCallback classes, and the result is updated in a TextView. ```java import com.tnkfactory.ad.TnkSession; import com.tnkfactory.ad.ServiceCallback; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final TextView pointView = findViewById(R.id.main_point); TnkSession.queryPoint(this, true, new ServiceCallback() { @Override public void onReturn(Context context, Object result) { Integer point = (Integer)result; pointView.setText(String.valueOf(point)); } }); } ``` -------------------------------- ### Track Purchase Events for Analytics in Java Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Record in-app purchase activities to measure conversion rates and ARPU metrics. This function utilizes `TnkSession.buyCompleted` to log specific item purchases, such as 'item_01' and 'item_02'. It requires the TnkSession class from the com.tnkfactory.ad package. ```java import com.tnkfactory.ad.TnkSession; // Track item_01 purchase TnkSession.buyCompleted(this, "item_01"); // Track item_02 purchase TnkSession.buyCompleted(this, "item_02"); ``` -------------------------------- ### Retrieve Placement Ad List Data Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Access raw advertisement data for custom UI implementation and advanced integration scenarios. This allows for custom display and interaction with ads. ```APIDOC ## Retrieve Placement Ad List Data ### Description Access raw advertisement data for custom UI implementation and advanced integration scenarios. ### Method (Not explicitly defined, assumed to be part of SDK initialization and event handling) ### Endpoint (Not applicable, SDK method) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example ```kotlin // SDK usage example lateinit var adPlacementView: AdPlacementView adPlacementView = tnkOfferwall.getAdPlacementView(this) placementContainerView.addView(adPlacementView) adPlacementView.placementEventListener = object : PlacementEventListener { override fun didAdDataLoaded(placementId: String, customData: String?) { val adList = adPlacementView.getAdList() val pubInfo = adPlacementView.getPubInfo() adList.forEach { adItem -> Log.d("AdData", "App: ${adItem.app_nm}, Points: ${adItem.pnt_amt}") } } // ... other callbacks } adPlacementView.loadAdList("open_ad") ``` ### Response #### Success Response (200) (Not applicable, handled via callbacks) #### Response Example (Not applicable) ``` -------------------------------- ### Track User Actions for Analytics Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Monitor specific user actions to analyze user behavior patterns and funnel performance. This helps in understanding user journeys and optimizing engagement. ```APIDOC ## Track User Actions for Analytics ### Description Monitor specific user actions to analyze user behavior patterns and funnel performance. ### Method `TnkSession.actionCompleted()` ### Endpoint (Not applicable, SDK method) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example ```java // Track resource download completion TnkSession.actionCompleted(this, "resource_loaded"); // Track user signup completion TnkSession.actionCompleted(this, "signup_completed"); // Track profile creation TnkSession.actionCompleted(this, "profile_entered"); // Track friend invitation TnkSession.actionCompleted(this, "friend_invite"); ``` ### Response #### Success Response (200) (Not applicable, SDK method) #### Response Example (Not applicable) ``` -------------------------------- ### Handle Ad Item Click Events Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Process individual ad click events when implementing custom ad list UI. This is crucial for tracking user engagement with specific ads. ```APIDOC ## Handle Ad Item Click Events ### Description Process individual ad click events when implementing custom ad list UI. ### Method (Not explicitly defined, assumed to be part of SDK initialization and event handling) ### Endpoint (Not applicable, SDK method) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example ```kotlin // SDK usage example within a ViewHolder adPlacementView.onItemClick(adItem.app_id) { success, errorMessage -> if (success) { Log.d("AdClick", "Successfully opened ad: ${adItem.app_nm}") } else { showError(errorMessage) Log.e("AdClick", "Failed: $errorMessage") } } ``` ### Response #### Success Response (200) (Not applicable, handled via callbacks) #### Response Example (Not applicable) ``` -------------------------------- ### Withdraw All Points (Java) Source: https://context7.com/tnkfactory/tnk_sdk_rwd_br/llms.txt Removes all accumulated points from a user's account in a single operation. This function requires a reason string for the withdrawal and a callback to handle the result. It returns the total number of points withdrawn. ```java import com.tnkfactory.ad.TnkSession; import com.tnkfactory.ad.ServiceCallback; @Override public void onClick(View v) { TnkSession.withdrawPoints(MainActivity.this, "user_delete", true, new ServiceCallback() { @Override public void onReturn(Context context, Object result) { int withdrawnPoints = (Integer)result; Log.d("tnkad", "Withdrawn points: " + withdrawnPoints); pointView.setText("0"); } }); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.