Logo
Administrator
To change from AdMob to StartApp ads in your Android project, you'll need to replace the AdMob-related code with StartApp's SDK and ad integration. Below are the steps to achieve this:

1. Remove AdMob Dependencies
Remove the AdMob dependencies from your build.gradle file. These lines typically look like this:

gradle
Copy
implementation 'com.google.android.gms:play-services-ads:20.6.0'
2. Add StartApp Dependencies
Add the StartApp SDK dependency to your build.gradle file:

gradle
Copy
implementation 'com.startapp:inapp-sdk:4.10.+'
3. Initialize StartApp SDK
In your MainActivity.java, initialize the StartApp SDK in the onCreate method:

java
Copy
import com.startapp.sdk.adsbase.StartAppSDK;

Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize StartApp SDK
StartAppSDK.init(this, "Your_StartApp_App_ID", true);
}
Replace "Your_StartApp_App_ID" with your actual StartApp App ID.

4. Replace AdMob Banner Ads with StartApp Banner Ads
In your UtilsAdmob.java, replace the AdMob banner ad code with StartApp banner ad code:

java
Copy
import com.startapp.sdk.ads.banner.Banner;
import com.startapp.sdk.ads.banner.BannerListener;

public class UtilsAdmob {
private Banner startAppBanner;

protected void prepare_banner() {
if (!enable_banner) return;

// Remove AdMob banner code
// mAdView = activity.findViewById(R.id.adView);

// Add StartApp banner
startAppBanner = new Banner(activity);
LinearLayout bannerLayout = activity.findViewById(R.id.adView);
bannerLayout.addView(startAppBanner);

startAppBanner.setBannerListener(new BannerListener() {
Override
public void onReceiveAd(View view) {
// Banner ad loaded
}

Override
public void onFailedToReceiveAd(View view) {
// Banner ad failed to load
}

Override
public void onImpression(View view) {
// Banner ad impression recorded
}

Override
public void onClick(View view) {
// Banner ad clicked
}
});

startAppBanner.loadAd();
}

protected void show_banner(Boolean visible) {
if (startAppBanner != null) {
startAppBanner.setVisibility(visible ? View.VISIBLE : View.GONE);
}
}

public void on_pause() {
if (startAppBanner != null) {
startAppBanner.pause();
}
}

public void on_resume() {
if (startAppBanner != null) {
startAppBanner.resume();
}
}

public void on_destroy() {
if (startAppBanner != null) {
startAppBanner.destroy();
}
}
}
5. Replace AdMob Interstitial Ads with StartApp Interstitial Ads
Replace the AdMob interstitial ad code with StartApp interstitial ad code:

java
Copy
import com.startapp.sdk.adsbase.StartAppAd;

public class UtilsAdmob {
private StartAppAd startAppInterstitial;

protected void prepare_inter() {
if (!enable_inter) return;

// Initialize StartApp interstitial
startAppInterstitial = new StartAppAd(activity);
}

public void show_inter() {
if (!enable_inter) return;

if (startAppInterstitial != null) {
startAppInterstitial.showAd();
}
}
}
6. Replace AdMob Rewarded Ads with StartApp Rewarded Ads
Replace the AdMob rewarded ad code with StartApp rewarded ad code:

java
Copy
import com.startapp.sdk.adsbase.StartAppAd;
import com.startapp.sdk.adsbase.adlisteners.AdEventListener;

public class UtilsAdmob {
private StartAppAd startAppRewarded;

public void prepare_reward() {
if (!enable_reward) return;

// Initialize StartApp rewarded ad
startAppRewarded = new StartAppAd(activity);
}

public void show_reward() {
if (startAppRewarded != null) {
startAppRewarded.loadAd(StartAppAd.AdMode.REWARDED_VIDEO, new AdEventListener() {
Override
public void onReceiveAd(com.startapp.sdk.adsbase.Ad ad) {
startAppRewarded.showAd();
is_rewarded = "yes";
activity.runOnUiThread(new Runnable() {
Override
public void run() {
activity.reward(is_rewarded);
}
});
}

Override
public void onFailedToReceiveAd(com.startapp.sdk.adsbase.Ad ad) {
is_rewarded = "no";
}
});
}
}
}
7. Remove AdMob Initialization
Remove the AdMob initialization code from UtilsAdmob.java:

java
Copy
// Remove this code
MobileAds.initialize(activity, new OnInitializationCompleteListener() {
Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
8. Update Layout Files
Ensure that your layout files (e.g., activity_main.xml) have the correct LinearLayout or RelativeLayout for the StartApp banner ad. The id should match the one used in the UtilsAdmob class:

xml
Copy

Run HTML
9. Update ProGuard Rules (if applicable)
If you are using ProGuard, add the following rules to your proguard-rules.pro file:

pro
Copy
-keep class com.startapp.** { *; }
-dontwarn com.startapp.**
10. Testing
Finally, test your app to ensure that the StartApp ads are loading correctly and that the ad eve
4 months ago

No replys yet!

It seems that this publication does not yet have any comments. In order to respond to this publication from Administrator , click on at the bottom under it