해당 문서는 BuzzAd Ext.point SDK의 광고 지면 타입 중 하나인, Pop Type 을 연동하는 문서입니다. Pop Type 은 쳇헤드 (Chat Head) 를 사용하여 앱 밖에서도 광고 참여 여부를 확인할 수 있습니다. Pop Feed 를 통해 앱 지면 바깥에서도 광고를 참여할 수 있으며, 클릭을 통해 앱으로 이동하여 유저의 앱 사용을 크게 증가시킵니다.
위의 과정 중 완료되지 않은 항목이 있다면, 이전 단계의 연동을 먼저 완료해야 합니다.
minSdkVersion
15 혹은 그 이상compileSdkVersion
29 혹은 그 이상[1] build.gradle
의 dependencies 에 아래의 코드를 제거해야 합니다.
repositories { maven { url "https://dl.buzzvil.com/public/maven" } } ... dependencies { // 버전 정보는 이전 단계에서 적용했으니 생략합니다. implementation ("com.buzzvil:buzzad-benefit:2.X.X") { ... // 아래 코드를 제거해야 합니다. exclude group: 'com.buzzvil', module: 'buzzad-benefit-pop' ... } } |
다음의 코드를 추가해야 합니다. 예시 코드에서 추가 항목 외의 입력 사항은 기본 값으로 작성되어 있습니다.
public class App extends Application { @Override public void onCreate() { final BuzzAdBenefitExtauthConfig extauthConfig = new BuzzAdBenefitExtauthConfig.Builder(this) .setAppIcon(context.getApplicationInfo().getIcon()) .setThemeColor(Color.parseColor("#F93F5A")) .build(); final BuzzAdBenefitExtauthInstaller extauthInstaller = new BuzzAdBenefitExtauthInstaller(extauthConfig); // (1) POP Config 를 추가해야 합니다. // 예시에 적힌 "Pop_Unit_Id" 를 '버즈빌에서 발급한 Unit Id'로 교체해 주세요. final PopConfig popConfig = new PopConfig.Builder(getApplicationContext(), "Pop_Unit_Id") .build(); final BuzzAdBenefitConfig buzzAdBenefitConfig = extauthInstaller.installTo(new BuzzAdBenefitConfig.Builder(this)) // (2) add 로 Benefit Config 에 Pop Config 를 추가해야 합니다. // 예시에 적힌 "Pop_Unit_Id" 를 '버즈빌에서 발급한 Unit Id'로 교체해 주세요. .add(popConfig) .build(); BuzzAdBenefit.init(this, buzzAdBenefitConfig); } } |
[1] PopConfig
를 생성한 뒤, 발급받은 Unit Id 를 설정합니다.
[2] '[Ext.point] 공통 적용 항목 연동' 단계에서 생성한 BuzzAdBenefitConfig
에 PopConfig
를 추가합니다.
다른 앱 위에 그리기
권한을 이미 가지고 있다면 해당 과정은 넘어가도 됩니다.Pop 을 실행하기 위해 다른 앱 위에 그리기
권한을 획득해야 합니다. 이 권한은 사용자가 직접 설정에서 다른 앱 위에 그리기 옵션을 활성화하여 획득할 수 있습니다. 사용자가 해당 옵션을 활성화시키지 않으면 Pop을 실행할 수 없습니다. SDK에서는 BuzzAdPop 클래스를 통해 권한 활성화가 되어 있지 않을 경우, 유저가 설정에서 권한을 활성화하도록 안내하고 있습니다.
[1] Pop 에 권한 설정을 할 Activity 에 BuzzAdPop
을 추가합니다.
private BuzzAdPop buzzAdPop; |
[2] Activity의 onCreate
에 Pop의 unit id를 이용하여 BuzzAdPop의 인스턴스를 추가합니다.
this.buzzAdPop = new BuzzAdPop(context, "POP_UNIT_ID"); |
[3] 다음은 앱이 필요한 권한이 있는지 확인하고 없다면 권한을 얻도록 안내하는 코드입니다.
public static final int REQUEST_CODE_SHOW_POP = 1024; public void enablePop() { BuzzAdPop buzzAdPop = new BuzzAdPop("POP_UNIT_ID"); if (buzzAdPop.hasPermission(context)) { // Show pop } else { buzzAdPop.requestPermissionWithDialog((Activity) context, new PopOverlayPermissionConfig.Builder(R.string.pop_name) .settingsIntent(OverlayPermission.createIntentToRequestOverlayPermission(context)) .requestCode(REQUEST_CODE_SHOW_POP) .build() ); } } |
[4] 사용자가 설정에서 다른 앱 위에 그리기
권한을 활성화하면, 이전 Activity로 돌아오게 됩니다. 이때 Intent 로 result 값이 넘어오며, 이 값을 통해 설정에서 권한이 활성화된 것을 알 수 있습니다.
import static com.buzzvil.lib.buzzsettingsmonitor.SettingsMonitor.KEY_SETTINGS_REQUEST_CODE; import static com.buzzvil.lib.buzzsettingsmonitor.SettingsMonitor.KEY_SETTINGS_RESULT; public class MainActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (getIntent().getBooleanExtra(KEY_SETTINGS_RESULT, false) && getIntent().getIntExtra(KEY_SETTINGS_REQUEST_CODE, 0) == REQUEST_CODE_SHOW_POP) { // Permission granted } } } |
BuzzAdPop.preloadAndShowPop()
함수를 호출하여 Pop 을 활성화합니다. 이후 foreground service 가 켜져, 화면이 다시 켜질 때마다 Pop 이 화면에 나타나게 됩니다.
Pop의 원활한 실행을 위해 광고를 미리 로드하고 Pop 이 보이도록 BuzzAdPop.preloadAndShowPop()
을 실행합니다.
BuzzAdPop buzzAdPop = new BuzzAdPop(context, "POP_UNIT_ID"); buzzAdPop.preloadAndShowPop(context); |
다른 앱 위에 그리기
권한 획득이 이루어지는지 확인Pop Config 는 Pop의 아이콘, Pop이 나타날 때의 위치 등 Look & Feel 을 설정할 수 있습니다. POP 디자인 가이드 문서 에서 이미지 예시를 직접 확인할 수 있습니다.
[1] 대부분의 항목은 기본값으로 설정되어 있습니다. 다른 값으로 설정하려면 아래의 'PopConfig의 필드 더보기'를 내의 해당 항목을 추가해야 합니다. (아래를 클릭하여 확인할 수 있습니다.)
|
[2] 변경하려는 값을 모두 적용한 뒤, build()
함수를 호출합니다.
new PopConfig.Builder(getApplicationContext(), UNIT_ID_POP).build(); |
[1] Pop을 클릭해서 나오는 Pop Feed 의 뷰를 설정할 수 있습니다. Feed Type과 겹치는 내용이 많으니 Feed Type 문서(링크)를 참고해 주세요.
[2] 다음은 Feed 뷰에서 광고와 컨텐츠를 모두 활성화 하고 컨텐츠 클릭시에 외부 Activity로 넘어가지 않고 내부 브라우저로 램딩되는 Feed를 만드는 코드입니다.
FeedConfig feedconfig = new FeedConfig.Builder(getApplicationContext(), "UNIT_ID_POP") .articlesEnabled(true) .feedToolbarHolderClass(DefaultPopToolbarHolder.class) // Pop의 default 툴바를 사용하고 싶은 경우 추가 .build()) |
2.3.0 버전부터 |
Pop을 실행하고 있는 동안, Pop이 실행 중이라는 Service Notification 을 보여줍니다. Notification의 내용을 결정할 수 있습니다. 앱의 Tone & Manner 를 반영하여 변경합니다. (아래를 클릭하여 확인할 수 있습니다.)
|
위에서 설명된 PopConfig, FeedConfig, PopNotificationConfig를 생성하고 나면, 아래와 같이 popConfig 를 설정할 수 있습니다. 아래의 코드는 적용 예시입니다.
final PopNotificationConfig popNotificationConfig = new PopNotificationConfig.Builder(getApplicationContext()) .smallIconResId(R.mipmap.ic_launcher) .titleResId(R.string.pop_notification_title) .textResId(R.string.pop_notification_text) .colorResId(R.color.colorPrimary) .notificationId(NOTIFICATION_ID) .build(); final PopConfig popConfig = new PopConfig.Builder(getApplicationContext(), UNIT_ID_POP) .initialSidePosition(new SidePosition(SidePosition.Side.RIGHT, 0.6f)) .initialPopIdleMode(PopConfig.PopIdleMode.INVISIBLE) .feedConfig(feedConfig) // optional .popNotificationConfig(popNotificationConfig) .build(); final BuzzAdBenefitConfig buzzAdBenefitConfig = new BuzzAdBenefitConfig.Builder(context) .add(popConfig) .build(); BuzzAdBenefit.init(this, buzzAdBenefitConfig); |
기본적으로 Service Notification 을 클릭 했을 때 Pop 을 다시 보이는 기능을 제공합니다. 하지만 개발 환경에 따라 Service Notification 을 다른 형식으로 사용해야 할 경우, Custom Service Notification 을 등록하여 사용할 수 있습니다.
// (1) PopControlService 를 상속받아 class 를 만듭니다. public class CustomControlService extends PopControlService { // (2) buildForegroundNotification 함수를 오버라이드 합니다. @Override protected Notification buildForegroundNotification(@NonNull String unitId, @NonNull PopNotificationConfig popNotificationConfig) { // (3) (optional) getPopPendingIntent 를 통해 click 시 Pop Icon 을 띄우는 기능을 하는 PendingIntent 를 만들 수 있습니다. PendingIntent popPendingIntent = getPopPendingIntent(unitId, this); NotificationCompat.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // (4) (optional) notificationChannel 을 생성해 등록합니다. createNotificationChannelIfNeeded(); builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); } else { builder = new NotificationCompat.Builder(this); } // (5) (optional) CustomContolService 에서 사용할 View 를 등록합니다. RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.view_custom_notification); builder.setSmallIcon(popNotificationConfig.getSmallIconResId()) .setContent(remoteView) .setContentIntent(popPendingIntent) .setPriority(PRIORITY_LOW) .setShowWhen(false); if (popNotificationConfig.getColor() == null) { builder.setColor(popNotificationConfig.getColor()); } return builder.build(); } @TargetApi(Build.VERSION_CODES.O) private void createNotificationChannelIfNeeded() { final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) { final NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW); channel.setShowBadge(false); notificationManager.createNotificationChannel(channel); } } } |
[1] PopControlService
를 상속받아 class 를 만듭니다.
[2] buildForegroundNotification
함수를 오버라이드 합니다.
[3] (선택 사항) getPopPendingIntent
를 통해 클릭시 Pop Icon 을 띄우는 PendingIntent 를 만들 수 있습니다. 해당 기능 대신 필요한 기능을 PendingIndent 로 사용할 수 있습니다.
[4] (선택 사항) notificationChannel 을 생성해 등록합니다.
[5] (선택 사항) RemoteViews
, setContent
를 사용해 CustomContolService 에서 사용할 View 를 등록합니다.
[1] PopConfig.controlService(@NonNull Class<? extends PopControlService> popControlServiceClass)
를 사용해 Custom Service Notification 을 등록합니다.
final PopNotificationConfig popNotificationConfig = new PopNotificationConfig.Builder() .smallIconResId(R.drawable.ic_notification_pop_gift) .notificationId(NOTIFICATION_ID) .build(); final PopConfig popConfig = new PopConfig.Builder(getApplicationContext(), UNIT_ID_POP) .initialSidePosition(new SidePosition(SidePosition.Side.RIGHT, 0.6f)) .initialPopIdleMode(PopConfig.PopIdleMode.INVISIBLE) .controlService(CustomControlService.class) .build(); final BuzzAdBenefitConfig buzzAdBenefitConfig = new BuzzAdBenefitConfig.Builder(context) .add(popConfig) .build(); BuzzAdBenefit.init(this, buzzAdBenefitConfig); |
PopNotificationConfig 는 SmallIconResId 와 NotificationId 두 가지만 설정하면 됩니다.
<application ... <service android:name=".java.CustomControlService" /> </application> |
Config 설정 외에 디자인 가이드의 양이 많아, 효율적인 연동을 위해 해당 내용을 분리했습니다.