To discuss and provide feedback on our products, join the official AdMob Discord channel in the Google Advertising and Measurement Community server.

Use network specific APIs

  • Mediation networks sometimes offer custom ad features through their Android/iOS SDKs, accessible via platform channels in Flutter.

  • This guide demonstrates calling privacy APIs in AppLovin's SDK from Dart code using a method channel for Android and iOS.

  • You need to create a method channel in Dart, modify your native Android/iOS code to handle the calls, and then use the channel to invoke the APIs.

  • Detailed steps are provided for setting up the method channel and invoking the setIsAgeRestrictedUser and setHasUserConsent APIs for AppLovin.

  • Refer to the Android and iOS network documentation for information on specific APIs supported by other mediation networks.

Mediation networks may provide APIs in their own Android and iOS SDKs that allow for further ads customization. You can call these APIs from dart code by using a platform channel.

The following sample shows you how to call privacy APIs in AppLovin's Android and iOS SDKs from Dart.

Create a method channel in dart

In your dart code, create a method channel:

/// Wraps a method channel that makes calls to AppLovin privacy APIs.
classMyMethodChannel{
finalMethodChannel_methodChannel=
MethodChannel('com.example.mediationexample/mediation-channel');
/// Sets whether the user is age restricted in AppLovin.
Future<void>setAppLovinIsAgeRestrictedUser(boolisAgeRestricted)async{
return_methodChannel.invokeMethod(
'setIsAgeRestrictedUser',
{
'isAgeRestricted':isAgeRestricted,
},
);
}
/// Sets whether we have user consent for the user in AppLovin.
Future<void>setHasUserConsent(boolhasUserConsent)async{
return_methodChannel.invokeMethod(
'setHasUserConsent',
{
'hasUserConsent':hasUserConsent,
},
);
}
}

Modify your Android code

Set up a method channel to make API calls to the AppLovin SDK in Android:

publicclass MainActivityextendsFlutterActivity{
privatestaticfinalStringCHANNEL_NAME=
"com.example.mediationexample/mediation-channel";
@Override
publicvoidconfigureFlutterEngine(@NonNullFlutterEngineflutterEngine){
super.configureFlutterEngine(flutterEngine);
// Set up a method channel for calling APIs in the AppLovin SDK.
newMethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(),CHANNEL)
.setMethodCallHandler(
(call,result)->{
switch(call.method){
case"setIsAgeRestrictedUser":
AppLovinPrivacySettings.setIsAgeRestrictedUser(call.argument("isAgeRestricted"),context);
result.success(null);
break;
case"setHasUserConsent":
AppLovinPrivacySettings.setHasUserConsent(call.argument("hasUserConsent"),context);
result.success(null);
break;
default:
result.notImplemented();
break;
}
}
);
}
}

Modify your iOS code

Set up a method channel to make API calls to the AppLovin SDK in iOS:

@implementation AppDelegate
- (BOOL)application:(UIApplication*)application
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{
[GeneratedPluginRegistrantregisterWithRegistry:self];
// Set up a method channel for calling methods in 3P SDKs.
FlutterViewController*controller=(FlutterViewController*)self.window.rootViewController;
FlutterMethodChannel*methodChannel=[FlutterMethodChannel
methodChannelWithName:@"com.example.mediationexample/mediation-channel"
binaryMessenger:controller.binaryMessenger];
[methodChannelsetMethodCallHandler:^(FlutterMethodCall*call,FlutterResultresult){
if([call.methodisEqualToString:@"setIsAgeRestrictedUser"]){
[ALPrivacySettingssetIsAgeRestrictedUser:call.arguments[@"isAgeRestricted"]];
result(nil);
}elseif([call.methodisEqualToString:@"setHasUserConsent"]){
[ALPrivacySettingssetHasUserConsent:call.arguments[@"hasUserConsent"]];
result(nil);
}else{
result(FlutterMethodNotImplemented);
}
}];
}
@end

Use your MethodChannel in Dart

Now you can use your MyMethodChannel to call AppLovin privacy APIs from Dart:

/// An example widget for the home page of your app.
classHomePageextendsStatefulWidget{
@override
_HomePageStatecreateState()=>_HomePageState();
}
class_HomePageStateextendsState<HomePage>{

// Keep a reference to your MyMethodChannel.
staticMyMethodChannelplatform=MyMethodChannel();

@override
voidinitState(){
super.initState();
_updateAppLovinSettingsAndLoadAd();
}

Future<void>_updateAppLovinSettingsAndLoadAd()async{
// Update the AppLovin settings before loading an ad.
awaitplatform.setAppLovinIsAgeRestrictedUser(true);
awaitplatform.setHasUserConsent(false);
_loadAd();
}

void_loadAd(){
// TODO: Load an ad.
};
@override
Widgetbuild(BuildContextcontext){
// TODO: Build your widget.
}
}

More details on the APIs supported by other networks can be found in the Android and iOS documentation.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月16日 UTC.