Last active
November 25, 2022 23:44
-
-
Save saymanrifat/4ec2449965863e94ba78b56af9318112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1st Step:(Dependencies) | |
dependencies { | |
implementation 'com.applovin:applovin-sdk:11.5.3' | |
implementation("androidx.lifecycle:lifecycle-process:2.5.1") | |
} | |
2nd Step:(Manifest) | |
<meta-data | |
android:name="applovin.sdk.key" | |
android:value="sdk_key_here" /> | |
3d Step: (Create 2 Class >-- MyApplication & SaymanRifat) | |
SaymanRifat ----Start---[ | |
public class SaymanRifat | |
implements LifecycleObserver, MaxAdListener { | |
private final MaxAppOpenAd appOpenAd; | |
private final Context context; | |
//Ads ID here | |
private final String ADS_UNIT = "YOUR_AD_UNIT_ID"; | |
public SaymanRifat(final Context context) { | |
ProcessLifecycleOwner.get().getLifecycle().addObserver(this); | |
this.context = context; | |
appOpenAd = new MaxAppOpenAd(ADS_UNIT, context); | |
appOpenAd.setListener(this); | |
appOpenAd.loadAd(); | |
} | |
private void showAdIfReady() { | |
if (appOpenAd == null || !AppLovinSdk.getInstance(context).isInitialized()) return; | |
if (appOpenAd.isReady()) { | |
appOpenAd.showAd(ADS_UNIT); | |
} else { | |
appOpenAd.loadAd(); | |
} | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
public void onStart() { | |
showAdIfReady(); | |
} | |
@Override | |
public void onAdLoaded(final MaxAd ad) { | |
} | |
@Override | |
public void onAdLoadFailed(final String adUnitId, final MaxError error) { | |
} | |
@Override | |
public void onAdDisplayed(final MaxAd ad) { | |
} | |
@Override | |
public void onAdClicked(final MaxAd ad) { | |
} | |
@Override | |
public void onAdHidden(final MaxAd ad) { | |
appOpenAd.loadAd(); | |
} | |
@Override | |
public void onAdDisplayFailed(final MaxAd ad, final MaxError error) { | |
appOpenAd.loadAd(); | |
} | |
} | |
----END---] | |
MyApplication ----Start---] | |
public class MyApplication extends Application | |
{ | |
private static SaymanRifat appOpenManager; | |
@Override | |
public void onCreate() | |
{ | |
super.onCreate(); | |
AppLovinSdk.initializeSdk( this, new AppLovinSdk.SdkInitializationListener() | |
{ | |
@Override | |
public void onSdkInitialized(final AppLovinSdkConfiguration configuration) | |
{ | |
} | |
} ); | |
appOpenManager = new SaymanRifat( this ); | |
} | |
} | |
----END---] | |
4th Step:(Manifest) | |
android:name=".MyApplication" | |
5th Manifest (Optional): | |
Internet Permission: | |
<uses-permission android:name="android.permission.INTERNET"/> | |
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | |
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment