google_applovin_unity_ads 1.0.3 google_applovin_unity_ads: ^1.0.3 copied to clipboard
Ads Implement
Add the dependency in pubspec.yaml
:
PERSONAL PACKAGE #
dependencies:
... google_applovin_unity_ads: ^1.0.3
ADD ANDROID MANIFEST #
//PERMISSION
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
//META DATA
<applicaton
...
android:usesCleartextTraffic="true">
<meta-data
android:name="applovin.sdk.key"
android:value="ENTER APPLOVING SDK KEY" />
<meta-data
android:name="applovin.sdk.verbose_logging"
android:value="true" />
<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />
FOR ANDROID SPLASH SCREEN
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />
</application>
BUILD GRADLE #
multiDexEnabled true
targetSdkVersion 33
ADD MAIN.DART #
WidgetsFlutterBinding.ensureInitialized();
await APICALLINGMETHOD();
if ((apiModel?.comIptvM3UPlaylists ?? "").toString().isNotEmpty) {
GoogleApplovinUnityAds.initialize(
jsonEncode(apiModel?.comIptvM3UPlaylists).toString(),
callback: () => {runApp(const IPTV())});
}
ADD VERSION CODE FUNCTION
dependencies:
package_info_plus:
int versionCode = 1;
PackageInfo packageInfo = await PackageInfo.fromPlatform();
setState(() {
versionCode = int.parse(packageInfo.buildNumber);
print("11111111- ${versionCode}");
});
ADS_FILE.DART #
import 'package:flutter/material.dart';
import 'package:google_applovin_unity_ads/google_applovin_unity_ads.dart';
import 'package:google_applovin_unity_ads/native/controller.dart';
import 'package:sizer/sizer.dart';
import '../main.dart';
showIntraAds({Function? callback = null}) async {
if (apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode == versionCode) {
if (callback != null) {
callback();
}
} else {
GoogleApplovinUnityAds.showIntraAds(callback: callback);
}
}
Future<void> showRewardAds({Function? callback}) async {
if (apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode == versionCode) {
if (callback != null) {
callback();
}
} else {
GoogleApplovinUnityAds.showRewardAds(callback: callback);
}
}
bannerAds() {
print(" palsana ${apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode}");
print(" palsana ${versionCode}");
if (apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode == versionCode ||
apiModel!.comIptvM3UPlaylists.adsSequence.isEmpty) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.bannerAds();
}
fullNativeAds() {
if (apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode == versionCode ||
apiModel!.comIptvM3UPlaylists.adsSequence.isEmpty ||
(apiModel!.comIptvM3UPlaylists.adsSequence.length == 1 &&
apiModel!.comIptvM3UPlaylists.adsSequence[0] == "custom_ads")) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.nativeAds(
NativeSize(Size(double.infinity, 50.h)), "F",
error: Container(
height: 0,
));
}
mediumNativeAds() {
if (apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode == versionCode ||
apiModel!.comIptvM3UPlaylists.adsSequence.isEmpty ||
(apiModel!.comIptvM3UPlaylists.adsSequence.length == 1 &&
apiModel!.comIptvM3UPlaylists.adsSequence[0] == "custom_ads")) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.nativeAds(
NativeSize(Size(double.infinity, 25.h)), "M");
}
showOpenAd() {
if (apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode == versionCode ||
apiModel!.comIptvM3UPlaylists.adsSequence.isEmpty) {
return;
}
GoogleApplovinUnityAds.showOpenAds();
}
smallNativeAds() {
if (apiModel!.comIptvM3UPlaylists.adSetting.appVersionCode == versionCode ||
apiModel!.comIptvM3UPlaylists.adsSequence.isEmpty ||
(apiModel!.comIptvM3UPlaylists.adsSequence.length == 1 &&
apiModel!.comIptvM3UPlaylists.adsSequence[0] == "custom_ads")) {
return Container(
height: 0,
);
}
return GoogleApplovinUnityAds.nativeAds(
NativeSize(Size(double.infinity, 50.h)), "S");
}
class nativeAdsClass {}
OPEN ADS #
// abstract class for Open Ad
abstract class _OpenAdState<T extends StatefulWidget> extends State<T> with WidgetsBindingObserver {
bool isAdShow = false;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
print("CHECK On Resumed Called");
if(!isAdShow)
GoogleApplovinUnityAds.showOpenAds(callback: () => {
isAdShow = true
});
}
if (state == AppLifecycleState.paused) {
print("CHECK On Paused Called");
isAdShow = false;
}
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
}
APPLOVIN SDK KEY SETTING #
"app_lovin": {
"sdk_key": "l2eT38yPMONBdyKO3A",
"is_unlimited_ads": false,
"id_unit_banner": "def1da1bf25084e",
"id_unit_intra": "9657b7aa7d1430b",
"id_unit_native_multiple":
{
"small":"1d7452a63e76862",
"medium":"f330bac72f3dbf9",
"manual":"42a7734a713d7f5"
},
"rewared_ads_unit_id": "deda40e3d0a2840",
"is_banner_ads": true,
"is_interstitial_ads": true,
"is_native_ads": true,
"is_rewared_ads": true
}17
or
```xml
<applicaton ......... >
<meta-data android:name="applovin.sdk.key" android:value="l2eT38yPMONBdyKO3A" />
<meta-data android:name="applovin.sdk.verbose_logging" android:value="true" />
</application>