Penggunaan Lanjutan
StartApp Tech
Pembaharuan Terakhir: 15 Juli 2020 14:35
Bagian ini menjelaskan penggunaan lanjutan dan opsi penyesuaian pribadi dan tidak
wajib untuk integrasi.
Iklan Pengantara
Terapkan iklan pengantara dengan objek untuk mendapatkan kontrol lebih atas iklan
Anda, seperti menggunakan panggilan balik atau menggunakan beberapa iklan dengan
properti berbeda.
Untuk menginisialisasi objek iklan pengantara, buat variabel anggota dalam aktivitas
Anda sebagai berikut:
Sekarang Anda dapat menggunakan objek ini untuk melakukan operasi berikut:
Untuk menampilkan iklan setelah keluar dari aplikasi Anda saat menekan tombol
'Kembali', ganti metode onBackPressed () dan tambahkan metode
startAppAd.onBackPressed () SEBELUM metode super.onBackPressed () :
@Override
public void onBackPressed() {
startAppAd.onBackPressed();
super.onBackPressed();
}
MENAMPILKAN PENGANTARA
Panggil showAd () di tempat yang sesuai dalam aktivitas di mana Anda ingin
menampilkan Iklan:
We highly recommend using our Automatic mode, which automatically selects the best
Interstitial Ad to display, meaning the type of Ads that will generate the most revenue
for you.
To add an automatic Interstitial Ad, please refer to Interstitial Ads. If you do not wish to
use the automatic mode, startAppAd.loadAd() can be directed to load specific Ads to
be shown later using the AdMode parameter. The options for the AdMode parameter are:
When using this mode, the following additional methods must be implemented in the
Activity’s life-cycle:
1. Override the onSaveInstanceState(Bundle outState) method and add a call
to startAppAd.onSaveInstanceState(outstate).
Example:
@Override
protected void onSaveInstanceState (Bundle outState){
super.onSaveInstanceState(outState);
startAppAd.onSaveInstanceState(outState);
}
Example:
@Override
protected void onRestoreInstanceState (Bundle savedInstanceState){
startAppAd.onRestoreInstanceState(savedInstanceState);
super.onRestoreInstanceState(savedInstanceState);
}
@Override
public void onReceiveAd(Ad ad) {
}
@Override
public void onFailedToReceiveAd(Ad ad) {
}
Example:
IMPORTANT:
Do not call loadAd() from within onFailedToReceiveAd(). The SDK will
automatically try to reload an ad upon a failure.
ADDING A CALLBACK WHEN AN INTERSTITIAL AD IS SHOWN
startAppAd.showAd() can get a parameter implementation of AdDisplayListener. To
get a callback when an Ad is shown, pass the object that
implements AdDisplayListener (this may be your Activity) as a parameter of the
method. This object must implement the following methods:
@Override
public void adHidden(Ad ad) {
}
@Override
public void adDisplayed(Ad ad) {
}
@Override
public void adClicked(Ad ad) {
}
@Override
public void adNotDisplayed(Ad ad) {
}
Example:
startAppAd.showAd(new AdDisplayListener() {
@Override
public void adHidden(Ad ad) {
}
@Override
public void adDisplayed(Ad ad) {
}
@Override
public void adClicked(Ad ad) {
}
@Override
public void adNotDisplayed(Ad ad) {
}
});
Banner Ads
LOADING A BANNER
You can load a banner without attaching it to a view, enabling you to attach it when
available in a later stage.
banner.loadAd(adWidthDP, adHeightDP);
IMPORTANT:
Do not call loadAd() from within onFailedToReceiveAd(). The SDK will
automatically try to reload an ad upon a failure.
You can add a banner programmatically, instead of using the layout XML.
For example, this is a basic example of adding a center-aligned banner to the bottom of
the layout:
In order to hide an already displayed banner, find the banner's view and use
the hideBanner() method.
For example:
In order to show the banner again, simply use the showBanner() method.
Splash Ad
CUSTOMIZING SPLASH SCREEN
StartApp In-Ad provides two modes for displaying splash screens - Template and User-
defined. The template splash screen is a pre-defined template in which you can place
your own creatives, such as application name, logo and loading animation, as described
below. If you want to use your own splash screen, you can provide it as a layout, using
the user-defined mode.
StartAppAd.showSplash(this, savedInstanceState,
new SplashConfig()
.setTheme(SplashConfig.Theme.OCEAN)
.setAppName("Your Application Name")
.setLogo(R.drawable.your_360x360_logo) // resource ID
.setOrientation(SplashConfig.Orientation.LANDSCAPE)
);
NOTE:
for optimal appearance of your Splash screen on all device densities, provide a
logo of 360x360px and place it in the drawable folder of your project. If this folder
does not exist, then create it.
If you do not provide a logo, then StartApp In-App uses the default application
icon (as declared in the Manifest) and stretches it to 360x360px.
For a full description of the SplashConfig API, please refer to Splash Config API.
Example:
StartAppAd.showSplash(this, savedInstanceState,
new SplashConfig()
.setTheme(SplashConfig.Theme.USER_DEFINED)
.setCustomScreen(R.layout.your_splash_screen_layout_id)
);
The following describes the methods that you can use for customizing the Splash screen
displayed in a StartApp In-App Splash screen Ad.
Sets the Splash theme to Template mode or User-defined mode. Use one of the first
five options below to specify a design theme for the Template mode. The last option
sets the mode to User-Defined. You may refer to Customizing the Splash Screen for
more information about Splash screen modes.
Parameters
SplashConfig.Theme.DEEP_BLUE (default)
SplashConfig.Theme.SKY
SplashConfig.Theme.ASHEN_SKY
SplashConfig.Theme.BLAZE
SplashConfig.Theme.GLOOMY
SplashConfig.Theme.OCEAN
SplashConfig.Theme.USER_DEFINED – user-defined mode
Sets the splash layout to Custom mode. This is mandatory if you are using
SplashConfig.Theme.USER_DEFINED.
Parameters
Layout Resource ID
Parameters
String (default is the application name from the manifest).
Parameters
Drawable resource ID (default is the icon resource from the manifest).
Parameters
SplashConfig.Orientation.PORTRAIT (default)
SplashConfig.Orientation.LANDSCAPE
SplashConfig.Orientation.AUTO (use the device's orientation upon entering the
application)
Native Ads
To load your native ad, call the loadAd() method with a NativeAdPreferences object:
startAppNativeAd.loadAd(new NativeAdPreferences());
NOTE:
By default, StartAppNativeAd retrieves the image URL of the ad. The SDK is also
capable of auto-loading the image as a BITMAP object. This feature is turned off
by default. For enabling it, set autoBitmapDownload in NativeAdPreferences to
true (please refer to Ad's image configuration).
@Override
public void onFailedToReceiveAd(Ad arg0) {
// Native Ad failed to receive
}
});
@Override
public void onFailedToReceiveAd(Ad arg0) {
// Native Ad failed to receive
Log.e("MyApplication", "Error while loading Ad")
}
};
NOTE:
It is possible to get less ads than you requested. It is also possible that no ad will
be returned. In this case you will receive an empty array.
Parameters
adsNumber - integer of the ads number
Return Value
NatvieAdPreferences – current object
You can choose between two options to obtain the ad's image:
Parameters
adsNumber - integer of the ads number autoBitmapDownload - Boolean:
Return Value
NatvieAdPreferences – current object
Parameters
imageSize - imageSize can get the following values:
At the moment, sizes 5-6 can't be used together with sizes 0-4.
Return Value
NatvieAdPreferences – current object
Parameters
imageSize - imageSize can get the following values:
At the moment, sizes 5-6 can't be used together with sizes 0-4.
Return Value
NatvieAdPreferences – current object
Get the rating of the ad in the Google Play store. The rating range is 1-5.
Get the image URL of the ad, according to the selected size.
Get the secondary icon URL of the ad, according to the selected size.
Get the secondary icon of the ad as a pre-cached bitmap, if requested using the
NativeAdPreferences.setAutoBitmapDownload() method.
Get the ad's package name in the Google Play store (for example,
"com.startapp.quicksearchbox").
Child-Directed Ad Serving
In case your app target children, you can pass to StartApp an indication for a child user
by sending the user's age. StartApp will use it for applying a child-directed ad serving in
case of a child user (under the age of 16)
You can send the user age upon initialization, after providing your DevId and AppId,
pass the SDKAdPreferences object with its data:
StartAppSDK.init(this,
"Your App ID",
new SDKAdPreferences()
.setAge(35));
NOTE: Apps that flagged as Designated For Kids in StartApp Portal are treated
automatically as child-directed for all ad requests.
Adding Ad Tags
You can add tags to your ad placements. A tag is simply a free style string identifier that
can be attached to any ad. Ad Tags will help you optimize your monetization by finding
the right balance between ads and the perfect ad-viewing experience for your users.
For example, if you implement couple of interstitial ads in different places in your
application, you can give each of them a different tag, one of them could be
"Level1Complete", the other "AfterScoresBoard", then, you can monitor which placement
convert better and get more engagement from your users.
In order to add tags, you simply need to add them to the right places in your code:
AdPreferences prefs = new AdPreferences();
prefs.setAdTag("top_banner");
Banner banner = new Banner(this, prefs);
Interstitials
NOTE:
Ad Tags can only be named using English letters and no more than 200 characters
After getting some traffic, you could see those tags in the portal reports
automatically, without extra setup.
If you know your user's gender or age, StartApp can use it to serve better-targeted ads
which can increase your eCPM and revenue significantly.
Setelah inisialisasi, setelah memberikan DevId dan AppId Anda, teruskan objek
SDKAdPreferences dengan datanya:
StartAppSDK.init(this,
"Your App ID",
new SDKAdPreferences()
.setAge(35)
.setGender(Gender.FEMALE));
}