Skip to content
Muhammad Hammad edited this page Oct 31, 2024 · 11 revisions

AdManageKit Home

AdManageKit is an Android library designed to simplify the management of Google AdMob ads, billing using the Google Play Billing Library, and User Messaging Platform (UMP) consent. This library provides a streamlined approach to integrating ads and handling user consent for privacy compliance, while also offering a sample project to demonstrate its usage.

Features

  • AdMob Ads Management: Easily integrate and manage AdMob ads in your Android applications, including banner, interstitial, and native ads.
  • Firebase Auto Log Tracking Event, tROAS: Automatically track tROAS (Target Return on Ad Spend) and other ad metrics.
  • Billing Management: Seamless integration with the Google Play Billing Library to handle in-app purchases and subscriptions.
  • UMP Consent Management: Manage user consent using Google's User Messaging Platform (UMP) to comply with privacy regulations like GDPR and CCPA.
  • Sample Project: A fully functional sample project to demonstrate how to use the library effectively in your own apps.

Getting Started

Installation

  1. Add the library to your project:

    Add it in your root build.gradle at the end of repositories:

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            mavenCentral()
            maven { url 'https://jitpack.io' }
        }
    }

    Add the following to your build.gradle file in the dependencies section:

    implementation 'com.github.i2hammad:admanagekit:1.1.4'
  2. Sync your project with Gradle files.

Usage Overview

Initializing the Library

The AdsConsentManager should be initialized in the first activity of your application to ensure that the consent form is displayed to the user as required.

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Initialize the AdsConsentManager
        AdsConsentManager adsConsentManager = AdsConsentManager.getInstance(this);
        adsConsentManager.requestUMP(this, new UMPResultListener() {
            @Override
            public void onCheckUMPSuccess(boolean isConsentGiven) {
                if (isConsentGiven) {
                    // Initialize Ads here
                } else {
                    // Handle if consent is not given
                }

                if (adsConsentManager.canRequestAds()) {
                    // Proceed to the next action
                }
            }
        });
    }
}

Managing AdMob Ads

For displaying a banner ad, include the following code in your XML layout:

<com.i2hammad.admanagekit.admob.BannerAdView
    android:id="@+id/bannerAdView"
    android:layout_height="wrap_content"
    android:layout_width="match_parent" />

Use the following code to load a banner ad:

bannerAdView.loadBanner(this, "ca-app-pub-3940256099942544/9214589741")

// For collapsible banner ads
bannerAdView.loadCollapsibleBanner(this, "ca-app-pub-3940256099942544/2014213617", true)

For native ads, similar code snippets can be used for NativeBannerMedium, NativeBannerSmall, and NativeLarge views.

Handling In-App Purchases

AdManageKit simplifies handling in-app purchases using the Google Play Billing Library.

Initialize the Billing Client:

AppPurchase.getInstance().initBilling(getApplication(), Arrays.asList(new PurchaseItem("your_product_id", AppPurchase.TYPE_IAP.PURCHASE)));

Start a Purchase Flow:

AppPurchase.getInstance().purchase(activity, "your_product_id");

Handle Purchase Results:

AppPurchase.getInstance().setPurchaseListener(new PurchaseListener() {
    @Override
    public void onProductPurchased(String orderId, String originalJson) {
        // Handle successful purchase
    }

    @Override
    public void displayErrorMessage(String errorMessage) {
        // Handle error in purchase
    }

    @Override
    public void onUserCancelBilling() {
        // Handle user cancellation
    }
});

User Messaging Platform (UMP) Consent

To request user consent using UMP:

AdsConsentManager.getInstance(this).requestUMP(this, true, "TEST_DEVICE_ID", false, new UMPResultListener() {
    @Override
    public void onCheckUMPSuccess(boolean isConsentGiven) {
        if (isConsentGiven) {
            // Consent given, proceed
        } else {
            // Consent not given
        }
    }
});

Sample Project

A sample project is included in the app directory of the repository. It demonstrates how to use AdManageKit to manage ads, purchases, and user consent.

Running the Sample Project

  1. Clone the repository:

    git clone https://github.com/i2hammad/AdManageKit.git
  2. Open the sample project in Android Studio.

  3. Replace placeholders with your own AdMob IDs and configure your app in the Google Play Console for in-app purchases.

  4. Run the project on an Android device or emulator.

Contributing

Contributions are welcome! If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -m 'Add YourFeature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

If you find AdManageKit valuable and wish to support its ongoing development, consider buying me a cup of tea.
Buy me a coffee

For any questions or issues, please open an issue in this repository or contact me at hammadmughal0001@gmail.com.

Clone this wiki locally