### Initialize SDK and Load Native Ad
Source: https://docs.adpies.com/android/integration/native
Initializes the AdPie SDK with the application context and Media ID, then creates a `NativeAd` object using the Slot ID and the `NativeAdViewBinder`. Finally, it requests the ad by calling `loadAd()`.
```java
private NativeAd nativeAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// SDK 초기화로 앱실행 1회만 호출한다. (Main Activity 에 필수로 입력한다.)
AdPieSDK.getInstance().initialize(getApplicationContext(), "AdPie-Media-ID");
...
NativeAdViewBinder viewBinder = new NativeAdViewBinder.Builder(R.layout.adpie_native_ad) // Layout ID
.setIconImageId(R.id.native_ad_icon) // Icon ID
.setTitleId(R.id.native_ad_title) // Title ID
.setDescriptionId(R.id.native_ad_description) // Description ID
.setMainId(R.id.native_ad_main) // Main ID
.setCallToActionId(R.id.native_ad_cta) // Call-To-Action ID
.setOptOutId(R.id.native_optout) // Opt-out I
.build();
// 광고 연동을 위한 슬롯 ID를 필수로 입력한다.
nativeAd = new NativeAd(this, "AdPie-Slot-ID", viewBinder);
// 광고 호출
nativeAd.loadAd();
}
```
--------------------------------
### Add Glide Dependency for Image Handling
Source: https://docs.adpies.com/android/integration/native
Integrates the Glide library for efficient image loading and GIF support in native ads. Requires Glide v4.4 or higher. Add the specified dependencies to your `build.gradle` file.
```gradle
dependencies {
// Glide 사용시
compile 'com.github.bumptech.glide:glide:4.+'
annotationProcessor 'com.github.bumptech.glide:compiler:4.+'
}
```
--------------------------------
### Create NativeAdViewBinder
Source: https://docs.adpies.com/android/integration/native
Creates a `NativeAdViewBinder` object to map the layout IDs defined in XML to the corresponding native ad elements (icon, title, description, main image, CTA, opt-out). This is crucial for the SDK to populate the ad correctly.
```java
NativeAdViewBinder viewBinder = new NativeAdViewBinder.Builder(R.layout.adpie_native_ad) // Layout ID
.setIconImageId(R.id.native_ad_icon) // Icon ID
.setTitleId(R.id.native_ad_title) // Title ID
.setDescriptionId(R.id.native_ad_description) // Description ID
.setMainId(R.id.native_ad_main) // Main ID
.setCallToActionId(R.id.native_ad_cta) // Call-To-Action ID
.setOptOutId(R.id.native_optout) // Opt-out ID
.build();
```
--------------------------------
### Define Native Ad XML Layout
Source: https://docs.adpies.com/android/integration/native
Defines the layout structure for native ads, specifying the placement of elements like icon, title, description, main image, and call-to-action button. Refer to the SDK's template for guidance.
```xml
```
--------------------------------
### Ad Event Handling (APAdViewDelegate)
Source: https://docs.adpies.com/ios/integration/banner
Provides implementation examples for essential APAdViewDelegate methods to handle ad loading success, failure, and user interactions like leaving the application.
```swift
// ViewController.swift
import UIKit
import AdPieSDK
class ViewContorller: UIViewController, APAdViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
...
// 델리게이트 등록
adView.delegate = self
}
// MARK: - APAdView delegates
func adViewDidLoadAd(_ view: APAdView!) {
// 광고 표출 성공 후 이벤트 발생
}
func adViewDidFail(toLoadAd view: APAdView!, withError error: Error!) {
// 광고 요청 또는 표출 실패 후 이벤트 발생
// error code : error._code
// error message : error.localizedDescription
}
func adViewWillLeaveApplication(_ view: APAdView!) {
// 광고 클릭 후 이벤트 발생
}
}
```
--------------------------------
### Set Ad Targeting Parameters
Source: https://docs.adpies.com/android/integration/native
Configures targeting data for native ads, allowing customization based on gender, age, or year of birth. This data is passed to the `loadAd()` method to influence ad delivery and potentially increase revenue.
```java
TargetingData targetingData = new TargetingData.Builder()
.setGender(TargetingData.Gender.MALE)
.setAge(30)
.setYearOfBirthday(1970)
.build();
// 광고 요청시 타겟팅 정보를 넣어준다.
nativeAd.loadAd(targetingData);
```
--------------------------------
### AdPie SDK Gradle Dependencies
Source: https://docs.adpies.com/android/project-settings
Configure your project's build.gradle file to include the AdPie SDK via Jitpack and ensure Google Maven Repository is available. This step is crucial for downloading the SDK library.
```gradle
repositories {
// Google Maven Repository (Gradle 4.1 이상)
google()
/* Google Maven Repository (Gradle 4.1 미만)
maven {
url "https://maven.google.com"
}
*/
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.adxcorp:adpie-android-sdk:1.14.5'
}
```
--------------------------------
### AndroidManifest.xml Permissions
Source: https://docs.adpies.com/android/project-settings
Add necessary permissions to your AndroidManifest.xml file to allow the SDK to access the internet and network state, which are essential for ad delivery.
```xml
```
--------------------------------
### Handle Image Downloads Manually
Source: https://docs.adpies.com/android/integration/native
Configure the SDK to skip automatic image downloads by calling `setSkipDownload(true)` on the NativeAd object. When skipping downloads, you must manually load and set images within the `onAdLoaded` callback by retrieving image URLs from `NativeAdData` and setting them on the appropriate `ImageView` components.
```java
// 광고 연동을 위한 슬롯 ID를 필수로 입력한다.
nativeAd = new NativeAd(this, "AdPie-Slot-ID", viewBinder);
// SDK에서 리소스 다운로드를 하지 않기 위한 설정
ativeAd.setSkipDownload(true);
// 광고 리스너 사용
ativeAd.setAdListener(new com.gomfactory.adpie.sdk.NativeAd.AdListener() {
@Override
public void onAdLoaded(final NativeAdView nativeAdView) {
// 이미지 다운로드 및 설정이 필요
NativeAdData nativeAdData = nativeAdView.getNativeAdData();
String iconImageUrl = nativeAdData.getIconImageUrl();
ImageView iconImageView = nativeAdView.getIconImageView();
String mainImageUrl = nativeAdData.getMainImageUrl();
ImageView mainImageView = nativeAdView.getMainImageView();
}
});
// 광고 호출
ativeAd.loadAd();
```
--------------------------------
### ProGuard Configuration Rules
Source: https://docs.adpies.com/android/project-settings
Add these ProGuard rules to your proguard-rules.pro file to prevent the AdPie SDK and Google Play Services classes from being stripped or obfuscated during the build process.
```proguard
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keep class com.google.android.gms.ads.** { *; }
-dontwarn com.google.android.gms.ads.**
-keep class com.gomfactory.** { *; }
-dontwarn com.gomfactory.**
-dontwarn com.bumptech.glide.**
```
--------------------------------
### AndroidManifest.xml Activity Declarations
Source: https://docs.adpies.com/android/project-settings
Declare required activities within the <application> tag in AndroidManifest.xml. This includes activities for InAppBrowser (SDK v1.9+), Interstitial ads, and VideoFullScreenActivity (SDK v1.2+ for video ads).
```xml
```
--------------------------------
### Import SDK and Adopt Delegate
Source: https://docs.adpies.com/ios/integration/banner
Demonstrates importing the AdPie SDK and adopting the APAdViewDelegate protocol in your ViewController for both Swift and Objective-C.
```swift
// ViewController.swift
import UIKit
import AdPieSDK
class ViewController: UIViewController, APAdViewDelegate {
}
```
```objective-c
// ViewController.h
#import
#import
@interface ViewController : UIViewController
@end
```
--------------------------------
### Set NativeAd Listener for Events
Source: https://docs.adpies.com/android/integration/native
Implement an AdListener to receive callbacks for various ad events such as loading completion, failure, display, and clicks. This allows for custom handling of the ad lifecycle. For ad request or display failures, error codes can be used to determine the reason.
```java
nativeAd.setAdListener(new com.gomfactory.adpie.sdk.NativeAd.AdListener() {
@Override
public void onAdLoaded(final NativeAdView nativeAdView) {
// 광고 로딩 완료 후 이벤트 발생
// 광고 요청 후 즉시 노출하고자 할 경우 아래의 코드를 추가한다.
ViewGroup adContainer = (ViewGroup)findViewById(R.id.ad_container);
adContainer.removeAllViews();
adContainer.addView(nativeAdView);
}
@Override
public void onAdFailedToLoad(int errorCode) {
// 광고 요청 또는 표출 실패 후 이벤트 발생
// error message -> AdPieError.getMessage(errorCode)
}
@Override
public void onAdShown() {
// 광고 표출 후 이벤트 발생
}
@Override
public void onAdClicked() {
// 광고 클릭 후 이벤트 발생
}
});
```
--------------------------------
### Request and Display Ad
Source: https://docs.adpies.com/ios/integration/banner
Illustrates the process of requesting and displaying an ad using the APAdView by setting the slot ID, root view controller, delegate, and calling the load method.
```swift
// ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
// 광고뷰에 Slot ID 입력
adView.slotId = "YOUR_SLOT_ID"
// 광고뷰의 RootViewController 등록 (Refresh를 위해 필요)
adView.rootViewController = self
// 델리게이트 등록
adView.delegate = self
// 광고 요청
adView.load()
}
```
```objective-c
// ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// 광고뷰에 Slot ID 입력
self.adView.slotId = @"YOUR_SLOT_ID_HERE";
// 광고뷰의 RootViewController 등록 (Refresh를 위해 필요)
self.adView.rootViewController = self;
// 델리게이트 등록
self.adView.delegate = self;
// 광고요청
[self.adView load];
}
```
--------------------------------
### Initialize AdPie SDK
Source: https://docs.adpies.com/flutter/integration/rewarded
Initializes the AdPie SDK, recommending initialization after app launch on Android and after ATT consent on iOS. Requires a Media ID obtained from the AdPie website.
```dart
void main() {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isAndroid) {
// AdPie SDK 초기화
AdPieSdk.initialize(mediaId);
} else {
initPlugin();
}
runApp(const MyApp());
}
Future initPlugin() async {
final TrackingStatus status =
await AppTrackingTransparency.trackingAuthorizationStatus;
if (status == TrackingStatus.notDetermined) {
final TrackingStatus status =
await AppTrackingTransparency.requestTrackingAuthorization();
}
final uuid = await AppTrackingTransparency.getAdvertisingIdentifier();
print("UUID: $uuid");
// AdPie SDK 초기화
AdPieSdk.initialize(mediaId);
}
```
--------------------------------
### Google Play Services Version Meta-data
Source: https://docs.adpies.com/android/project-settings
Include the Google Play Services version meta-data in your AndroidManifest.xml to ensure compatibility with the Google Play Services SDK.
```xml
```