-
Notifications
You must be signed in to change notification settings - Fork 4
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.
- 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.
-
Add the library to your project:
Add it in your root
build.gradleat 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.gradlefile in thedependenciessection:implementation 'com.github.i2hammad:admanagekit:1.1.4' -
Sync your project with Gradle files.
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
}
}
});
}
}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.
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
}
});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
}
}
});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.
-
Clone the repository:
git clone https://github.com/i2hammad/AdManageKit.git
-
Open the sample project in Android Studio.
-
Replace placeholders with your own AdMob IDs and configure your app in the Google Play Console for in-app purchases.
-
Run the project on an Android device or emulator.
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature). - Commit your changes (
git commit -m 'Add YourFeature'). - Push to the branch (
git push origin feature/YourFeature). - Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
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.
AdManageKit v3.3.4 | GitHub | API Docs | Report Issue | Buy me a coffee