Java源码示例:com.applovin.sdk.AppLovinSdk
示例1
public AppLovinCarouselView(Context context, AttributeSet attrs, int defStyleAttr, AppLovinSdk sdk, List<AppLovinNativeAd> nativeAds)
{
super( context, attrs, defStyleAttr );
if ( !isInEditMode() )
{
this.sdk = sdk;
this.cardStates = new HashMap<Integer, InlineCarouselCardState>();
this.nativeAds = nativeAds;
if ( context instanceof Activity )
{
parentActivity = (Activity) context;
}
renderActivityIndicator();
}
}
示例2
public void setUpView()
{
this.uiHandler = new Handler( Looper.getMainLooper() );
final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
inflater.inflate( R.layout.applovin_card_view, this, true );
bindViews();
renderActivityIndicator();
if ( sdk == null )
{
sdk = AppLovinSdk.getInstance( getContext() );
}
sdk.getNativeAdService().precacheResources( ad, this );
}
示例3
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate( savedInstanceState );
AppLovinSdk.getInstance( this ).initializeSdk( new AppLovinSdk.SdkInitializationListener()
{
@Override
public void onSdkInitialized(final AppLovinSdkConfiguration config)
{
// SDK finished initialization
}
} );
// Set an identifier for the current user. This identifier will be tied to various analytics events and rewarded video validation
AppLovinSdk.getInstance( this ).setUserIdentifier( "[email protected]" );
// Check that SDK key is present in Android Manifest
checkSdkKey();
}
示例4
/**
* Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server
* parameters, or Android Manifest.
*/
public static AppLovinSdk retrieveSdk(Bundle serverParameters, Context context) {
final String sdkKey =
(serverParameters != null) ? serverParameters.getString(ServerParameterKeys.SDK_KEY) : null;
final AppLovinSdk sdk;
if (!TextUtils.isEmpty(sdkKey)) {
sdk = AppLovinSdk.getInstance(sdkKey, new AppLovinSdkSettings(), context);
} else {
sdk = AppLovinSdk.getInstance(context);
}
sdk.setPluginVersion(BuildConfig.VERSION_NAME);
sdk.setMediationProvider(AppLovinMediationProvider.ADMOB);
return sdk;
}
示例5
@Override
public void initialize(
Context context,
InitializationCompleteCallback initializationCompleteCallback,
List<MediationConfiguration> mediationConfigurations) {
log(DEBUG, "Attempting to initialize SDK.");
if (!(context instanceof Activity)) {
initializationCompleteCallback.onInitializationFailed(
"AppLovin requires an Activity context to initialize.");
return;
}
Activity activity = (Activity) context;
if (AppLovinUtils.androidManifestHasValidSdkKey(activity)) {
AppLovinSdk.getInstance(activity).initializeSdk();
}
for (MediationConfiguration mediationConfig : mediationConfigurations) {
AppLovinSdk sdk = AppLovinUtils.retrieveSdk(mediationConfig.getServerParameters(), activity);
sdk.initializeSdk();
}
initializationCompleteCallback.onInitializationSucceeded();
}
示例6
@Override
public VersionInfo getSDKVersionInfo() {
String versionString = AppLovinSdk.VERSION;
String[] splits = versionString.split("\\.");
if (splits.length >= 3) {
int major = Integer.parseInt(splits[0]);
int minor = Integer.parseInt(splits[1]);
int patch = Integer.parseInt(splits[2]);
return new VersionInfo(major, minor, patch);
}
String logMessage =
String.format(
"Unexpected SDK version format: %s. Returning 0.0.0 for SDK version.", versionString);
Log.w(TAG, logMessage);
return new VersionInfo(0, 0, 0);
}
示例7
/**
* Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
*/
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
final AppLovinSdk sdk;
if ( !TextUtils.isEmpty( sdkKey ) )
{
sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
}
else
{
sdk = AppLovinSdk.getInstance( context );
}
return sdk;
}
示例8
/**
* Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
*/
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
final AppLovinSdk sdk;
if ( !TextUtils.isEmpty( sdkKey ) )
{
sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
}
else
{
sdk = AppLovinSdk.getInstance( context );
}
return sdk;
}
示例9
/**
* Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
*/
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
final AppLovinSdk sdk;
if ( !TextUtils.isEmpty( sdkKey ) )
{
sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
}
else
{
sdk = AppLovinSdk.getInstance( context );
}
return sdk;
}
示例10
/**
* Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server parameters, or Android Manifest.
*/
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras, final Context context)
{
final String sdkKey = serverExtras != null ? serverExtras.get( "sdk_key" ) : null;
final AppLovinSdk sdk;
if ( !TextUtils.isEmpty( sdkKey ) )
{
sdk = AppLovinSdk.getInstance( sdkKey, new AppLovinSdkSettings(), context );
}
else
{
sdk = AppLovinSdk.getInstance( context );
}
return sdk;
}
示例11
@Override
public void showInterstitial()
{
final AppLovinAd preloadedAd = dequeueAd( zoneId );
if ( preloadedAd != null )
{
final AppLovinSdk sdk = AppLovinSdk.getInstance( context );
final AppLovinInterstitialAdDialog interstitialAd = AppLovinInterstitialAd.create( sdk, context );
interstitialAd.setAdDisplayListener( this );
interstitialAd.setAdClickListener( this );
interstitialAd.setAdVideoPlaybackListener( this );
interstitialAd.showAndRender( preloadedAd );
}
else
{
log( ERROR, "Failed to show an AppLovin interstitial before one was loaded" );
listener.onAdFailedToLoad( AdRequest.ERROR_CODE_INTERNAL_ERROR );
}
}
示例12
/**
* Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server
* parameters, or Android Manifest.
*/
private static AppLovinSdk retrieveSdk(final Map<String, String> serverExtras,
final Context context) {
final String sdkKey = serverExtras != null ? serverExtras.get("sdk_key") : null;
final AppLovinSdk sdk;
if (!TextUtils.isEmpty(sdkKey)) {
sdk = AppLovinSdk.getInstance(sdkKey, new AppLovinSdkSettings(), context);
} else {
sdk = AppLovinSdk.getInstance(context);
}
return sdk;
}
示例13
@Override public void initializeNetwork(@NonNull Context context,
@Nullable Map<String, String> configuration,
@NonNull OnNetworkInitializationFinishedListener listener) {
AppLovinSdk.initializeSdk(context);
listener.onNetworkInitializationFinished(this.getClass(),
MoPubErrorCode.ADAPTER_INITIALIZATION_SUCCESS);
}
示例14
public void loadNativeAds(final int numAdsToLoad)
{
final AppLovinSdk sdk = AppLovinSdk.getInstance( getApplicationContext() );
sdk.getNativeAdService().loadNativeAds( numAdsToLoad, new AppLovinNativeAdLoadListener()
{
@Override
public void onNativeAdsLoaded(final List list)
{
// Native ads loaded; do something with this, e.g. render into your custom view.
runOnUiThread( new Runnable()
{
@Override
public void run()
{
log( "Native ad loaded, assets not retrieved yet." );
nativeAd = (AppLovinNativeAd) list.get( 0 );
precacheButton.setEnabled( true );
}
} );
}
@Override
public void onNativeAdsFailedToLoad(final int errorCode)
{
// Native ads failed to load for some reason, likely a network error.
// Compare errorCode to the available constants in AppLovinErrorCodes.
log( "Native ad failed to load with error code " + errorCode );
if ( errorCode == AppLovinErrorCodes.NO_FILL )
{
// No ad was available for this placement
}
// else if (errorCode == .... ) { ... }
}
} );
}
示例15
public InlineCarouselAdapter(Context context, AppLovinSdk sdk, AppLovinCarouselView parentView)
{
this.sdk = sdk;
this.context = context;
this.parentView = parentView;
this.existingCards = new SparseArray<WeakReference<InlineCarouselCardView>>();
}
示例16
private void checkSdkKey()
{
final String sdkKey = AppLovinSdk.getInstance( getApplicationContext() ).getSdkKey();
if ( "YOUR_SDK_KEY".equalsIgnoreCase( sdkKey ) )
{
new AlertDialog.Builder( this )
.setTitle( "ERROR" )
.setMessage( "Please update your sdk key in the manifest file." )
.setCancelable( false )
.setNeutralButton( "OK", null )
.show();
}
}
示例17
private Intent getContactIntent()
{
Intent intent = new Intent( Intent.ACTION_SENDTO );
intent.setType( "text/plain" );
intent.setData( Uri.parse( "mailto:" + "[email protected]" ) );
intent.putExtra( Intent.EXTRA_SUBJECT, "Android SDK support" );
intent.putExtra( Intent.EXTRA_TEXT, "\n\n\n---\nSDK Version: " + AppLovinSdk.VERSION );
return intent;
}
示例18
/**
* Toggling the sdk mute setting will affect whether your video ads begin in a muted state or not.
*/
private void toggleMute()
{
AppLovinSdk sdk = AppLovinSdk.getInstance( this );
sdk.getSettings().setMuted( !sdk.getSettings().isMuted() );
muteToggleMenuItem.setIcon( getMuteIconForCurrentSdkMuteSetting() );
}
示例19
private Drawable getMuteIconForCurrentSdkMuteSetting()
{
AppLovinSdk sdk = AppLovinSdk.getInstance( this );
int drawableId = sdk.getSettings().isMuted() ? R.drawable.mute : R.drawable.unmute;
if ( Build.VERSION.SDK_INT >= 22 )
{
return getResources().getDrawable( drawableId, getTheme() );
}
else
{
return getResources().getDrawable( drawableId );
}
}
示例20
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_interstitial_basic_integration );
adStatusTextView = (TextView) findViewById( R.id.status_label );
interstitialAd = AppLovinInterstitialAd.create( AppLovinSdk.getInstance( this ), this );
showButton = (Button) findViewById( R.id.showButton );
showButton.setOnClickListener( new View.OnClickListener()
{
@Override
public void onClick(View v)
{
showButton.setEnabled( false );
log( "Showing..." );
//
// Optional: Set ad load, ad display, ad click, and ad video playback callback listeners
//
interstitialAd.setAdLoadListener( InterstitialBasicIntegrationActivity.this );
interstitialAd.setAdDisplayListener( InterstitialBasicIntegrationActivity.this );
interstitialAd.setAdClickListener( InterstitialBasicIntegrationActivity.this );
interstitialAd.setAdVideoPlaybackListener( InterstitialBasicIntegrationActivity.this ); // This will only ever be used if you have video ads enabled.
interstitialAd.show();
}
} );
}
示例21
public AppLovinNativeAdListener(
AppLovinNativeAdapter adapter,
MediationNativeListener nativeListener,
AppLovinSdk sdk,
Context context,
NativeMediationAdRequest mediationAdRequest) {
mAdapter = adapter;
mNativeListener = nativeListener;
mSdk = sdk;
mContextWeakReference = new WeakReference<>(context);
mMediationAdRequest = mediationAdRequest;
}
示例22
@Override
public void requestNativeAd(
final Context context,
final MediationNativeListener mediationNativeListener,
final Bundle serverParameters,
final NativeMediationAdRequest nativeMediationAdRequest,
final Bundle mediationExtras) {
if (!nativeMediationAdRequest.isUnifiedNativeAdRequested()
&& !nativeMediationAdRequest.isAppInstallAdRequested()) {
String errorMessage =
createAdapterError(
ERROR_REQUIRES_UNIFIED_NATIVE_ADS,
"Failed to request native ad. "
+ "Unified Native Ad or App install Ad should be requested");
Log.e(TAG, errorMessage);
mediationNativeListener.onAdFailedToLoad(this, ERROR_REQUIRES_UNIFIED_NATIVE_ADS);
return;
}
if (!(context instanceof Activity)) {
String adapterError =
createAdapterError(
ERROR_CONTEXT_NOT_ACTIVITY, "AppLovin requires an Activity context to load ads.");
log(ERROR, "Failed to load native ad from AppLovin: " + adapterError);
mediationNativeListener.onAdFailedToLoad(
AppLovinNativeAdapter.this, ERROR_CONTEXT_NOT_ACTIVITY);
return;
}
final AppLovinSdk sdk = AppLovinUtils.retrieveSdk(serverParameters, context);
AppLovinNativeAdListener listener =
new AppLovinNativeAdListener(
this, mediationNativeListener, sdk, context, nativeMediationAdRequest);
sdk.getNativeAdService().loadNativeAds(1, listener);
}
示例23
public void loadAd() {
Context context = adConfiguration.getContext();
if (!(context instanceof Activity)) {
String adapterError =
createAdapterError(
ERROR_CONTEXT_NOT_ACTIVITY, "AppLovin requires an Activity context to load ads.");
Log.e(TAG, "Failed to load banner ad from AppLovin: " + adapterError);
callback.onFailure(adapterError);
return;
}
AppLovinAdSize adSize =
AppLovinUtils.appLovinAdSizeFromAdMobAdSize(context, adConfiguration.getAdSize());
if (adSize == null) {
String errorMessage =
createAdapterError(
ERROR_BANNER_SIZE_MISMATCH, "Failed to request banner with unsupported size.");
callback.onFailure(errorMessage);
return;
}
AppLovinSdk sdk = AppLovinUtils.retrieveSdk(adConfiguration.getServerParameters(), context);
adView = new AppLovinAdView(sdk, adSize, context);
adView.setAdDisplayListener(this);
adView.setAdClickListener(this);
adView.setAdViewEventListener(this);
// Load ad!
sdk.getAdService().loadNextAdForAdToken(adConfiguration.getBidResponse(), this);
}
示例24
@Override
public void initialize(final Context context, final MediationAdRequest adRequest, final String userId, final MediationRewardedVideoAdListener listener, final Bundle serverParameters, final Bundle networkExtras)
{
// SDK versions BELOW 7.2.0 require a instance of an Activity to be passed in as the context
if ( AppLovinSdk.VERSION_CODE < 720 && !( context instanceof Activity ) )
{
log( ERROR, "Unable to request AppLovin rewarded video. Invalid context provided." );
listener.onInitializationFailed( this, AdRequest.ERROR_CODE_INVALID_REQUEST );
return;
}
log( DEBUG, "Initializing AppLovin rewarded video..." );
this.context = context;
this.listener = listener;
if ( !initialized )
{
AppLovinSdk.initializeSdk( context );
AppLovinSdk.getInstance( context ).setPluginVersion( "AdMob-2.2.1" );
initialized = true;
}
listener.onInitializationSucceeded( this );
}
示例25
@Override
public void loadAd(final MediationAdRequest adRequest, final Bundle serverParameters, final Bundle networkExtras)
{
log( DEBUG, "Requesting AppLovin rewarded video with networkExtras: " + networkExtras );
// Zones support is available on AppLovin SDK 7.5.0 and higher
final String zoneId;
if ( AppLovinSdk.VERSION_CODE >= 750 && networkExtras != null && networkExtras.containsKey( "zone_id" ) )
{
zoneId = networkExtras.getString( "zone_id" );
}
else
{
zoneId = DEFAULT_ZONE;
}
// Check if incentivized ad for zone already exists
if ( GLOBAL_INCENTIVIZED_INTERSTITIAL_ADS.containsKey( zoneId ) )
{
incentivizedInterstitial = GLOBAL_INCENTIVIZED_INTERSTITIAL_ADS.get( zoneId );
}
else
{
// If this is a default Zone, create the incentivized ad normally
if ( DEFAULT_ZONE.equals( zoneId ) )
{
incentivizedInterstitial = AppLovinIncentivizedInterstitial.create( this.context );
}
// Otherwise, use the Zones API
else
{
incentivizedInterstitial = AppLovinIncentivizedInterstitial.create( zoneId, AppLovinSdk.getInstance( this.context ) );
}
GLOBAL_INCENTIVIZED_INTERSTITIAL_ADS.put( zoneId, incentivizedInterstitial );
}
incentivizedInterstitial.preload( this );
}
示例26
public AppLovinCarouselView(Context context, AttributeSet attrs, int defStyleAttr)
{
this( context, attrs, defStyleAttr, AppLovinSdk.getInstance( context ), null );
}
示例27
public AppLovinSdk getSdk()
{
return sdk;
}
示例28
public void setSdk(AppLovinSdk sdk)
{
this.sdk = sdk;
}
示例29
public AppLovinSdk getSdk()
{
return sdk;
}
示例30
public void setSdk(AppLovinSdk sdk)
{
this.sdk = sdk;
}