Difference between revisions of "Android SDK Getting Start"

From AdLocus
Jump to: navigation, search
(→‎取得您的 App Key)
 
(26 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
以下將說明您怎麼整入 AdLocus SDK.
 
以下將說明您怎麼整入 AdLocus SDK.
  
 +
自我檢查
 +
=== Android Studio ===
 +
* Gradle 中加入AdLocus  (Y/N)
 +
* Tool > Android > Sync Project With Gradle Files  (Y/N)
 +
 +
若您已完成上述檢查卻無法正確啟用相關服務, 請來信 support@adlocus.com , 我們將有專人與您聯繫.
  
 
== 取得您的 App Key ==
 
== 取得您的 App Key ==
−
** 至 http://adlocus.com/ 申請帳號並登入。
+
* 至 https://adlocus.com/ 點 <開發商> 申請帳號並登入。
−
** 在「應用程式」中「新增」您的應用程式並取得app key。
+
* 在「應用程式」中「新增」您的應用程式並取得app key。
  
 
== 準備將 SDK 加入到您的專案 ==
 
== 準備將 SDK 加入到您的專案 ==
−
* 將AdLocus SDK(adlocus_sdk_*.jar) 加入到專案步驟如下:
+
* [[Android_AddSDK|加入SDK]]
−
** 在專案底下建立 libs 資料夾 ( 在專案上按右鍵 > New > Folder,在 Folder name 填入 libs , Finish )
+
−
** 將 jar 複製到 libs 資料夾底下
+
−
* AndroidManifest.xml 中加入以下權限
+
−
<syntaxhighlight lang="java">
+
−
// Inapp
+
−
<uses-permission android:name="android.permission.INTERNET" />
+
−
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
+
−
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
+
−
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+
−
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
+
−
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
+
−
 
+
−
// Promotion
+
−
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+
−
<uses-permission android:name="android.permission.WAKE_LOCK" />
+
−
<uses-permission android:name="com.adlocus.permission.SEND" />
+
−
<permission android:name = "com.adlocus.permission.SEND" />
+
−
 
+
−
<service
+
−
android:name="com.adlocus.push.PushService"
+
−
android:process=":adlocus">
+
−
</service>
+
−
 
+
−
<receiver
+
−
android:enabled="true"
+
−
        android:process=":adlocus"
+
−
android:name="com.adlocus.push.PushReceive"
+
−
        android:permission="com.adlocus.permission.SEND">
+
−
<intent-filter>
+
−
<action android:name="android.intent.action.BOOT_COMPLETED" />
+
−
<category android:name="android.intent.category.DEFAULT" />
+
−
</intent-filter>
+
−
        <intent-filter>
+
−
                <action android:name="com.adlocus.action.RECEIVE" />
+
−
        </intent-filter>
+
−
</receiver>
+
−
 
+
−
</syntaxhighlight>
+
−
 
+
−
* 加入 Library Project 至您的專案中。
+
−
 
+
−
<syntaxhighlight lang="java">
+
−
 
+
−
 
+
−
 
+
−
</syntaxhighlight>
+
−
 
+
  
 
== InApp ==
 
== InApp ==
−
在 Activity 中加入以下程式碼
+
* [[Android_InApp|詳細說明]]
−
<syntaxhighlight lang="java">
+
−
import com.adlocus.*;
+
−
 
+
−
usLayout adlocusLayout =
+
−
new AdLocusLayout(this,
+
−
AdLocusLayout.AD_SIZE_BANNER, //設定廣告大小,通常為 Banner
+
−
your app key, //填入 app key
+
−
15); //設定輪播時間,最低 15 秒,-1 為不輪播只顯示一則
+
−
 
+
−
// 設定輪播動畫,預設為淡入,範例設定為隨機動畫
+
−
adlocusLayout.setTransitionAnimation(AdLocusLayout.ANIMATION_RANDOM);
+
−
LinearLayout.LayoutParams adlocusLayoutParams = new LinearLayout.LayoutParams(
+
−
ViewGroup.LayoutParams.WRAP_CONTENT,
+
−
ViewGroup.LayoutParams.WRAP_CONTENT);
+
−
// 設定置中
+
−
adlocusLayoutParams.gravity = Gravity.CENTER;
+
−
// 加入到你的 layout 中
+
−
yourLayout.addView(adlocusLayout, adlocusLayoutParams);
+
−
yourLayout.setGravity(Gravity.CENTER_HORIZONTAL);
+
−
yourLayout.invalidate();
+
−
</syntaxhighlight>
+
−
 
+
−
AD SIZE 說明:
+
−
AdSize Constant Size (WxH) Availability
+
−
# AD_SIZE_BANNER 320x50 (dp) 手機及平板
+
−
# AD_SIZE_IAB_MRECT 300x250 (dp) 平板
+
−
# AD_SIZE_IAB_LEADERBOARD 728x90 (dp) 平板
+
−
 
+
−
注意 : 請確保 layout 的空間大於等於您所設定的 AD size,否則將不會展示廣告。
+
−
 
+
−
** 監聽事件.
+
−
加入以下程式碼。
+
−
<syntaxhighlight lang="java">
+
−
adlocusLayout.setListener(new AdListener()
+
−
{
+
−
@Override
+
−
public void onReceiveAd(Ad adView)
+
−
{
+
−
AdLocusLayout layout = (AdLocusLayout)adView;
+
−
}
+
−
@Override
+
−
public void onFailedToReceiveAd(Ad adView, AdLocusLayout$ErrorCode errorCode)
+
−
{
+
−
AdLocusLayout layout = (AdLocusLayout) adView;
+
−
switch (errorCode)
+
−
{
+
−
case NO_FILL:
+
−
//無廣告展示.
+
−
break;
+
−
case INVAILD_KEY:
+
−
//錯誤的APP KEY.
+
−
break;
+
−
case NETWORK_ERROR:
+
−
//網路連線問題
+
−
break;
+
−
case SERVICE_ERROR:
+
−
//伺服器忙碌或維護中
+
−
break;
+
−
default:
+
−
break;
+
−
}
+
−
    }
+
−
});
+
−
</syntaxhighlight>
+
  
 
== Promotion ==
 
== Promotion ==
−
適地性優惠通知服務是依據全區定向或特定地理位置定向提供與您的使用者最適合的主動式訊息。
+
* [[Android_Promotion|詳細說明]]
  
−
使用此服務會產生一個 service 在背景運行。
+
== Interstitial ==
 +
* [[Android_Interstitial|詳細說明]]
  
 +
== Video ==
 +
* [[Android_Video|詳細說明]]
  
 +
== AdMob Mediation ==
 +
* [[Android_AdMM|詳細說明]]
  
−
 
+
== 測試模式與觀眾定向(Optional) ==
−
 
+
當您完成 SDK 整合後,您可透過設定下列參數開啟測試模式(測試模式下的互動在平台上將不記錄).
−
 
+
−
 
+
−
 
+
−
 
+
−
 
+
−
 
+
−
 
+
−
9.3AndroidManifest.xml 加入權限。
+
−
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+
−
<uses-permission android:name="android.permission.WAKE_LOCK" />
+
−
<uses-permission android:name="com.adlocus.permission.SEND" />
+
−
<permission android:name = "com.adlocus.permission.SEND" />
+
−
9.4AndroidManifest.xml 的 Application 底下加入下列程式碼。
+
−
 
+
−
<service
+
−
android:name="com.adlocus.push.PushService"
+
−
android:process=":adlocus">
+
−
</service>
+
−
 
+
−
<receiver
+
−
android:enabled="true"
+
−
android:process=":adlocus"
+
−
android:name="com.adlocus.push.PushReceive"
+
−
android:permission="com.adlocus.permission.SEND"
+
−
>
+
−
<intent-filter>
+
−
<action android:name="android.intent.action.BOOT_COMPLETED" />
+
−
<category android:name="android.intent.category.DEFAULT" />
+
−
</intent-filter>
+
−
<intent-filter>
+
−
<action android:name="com.adlocus.action.RECEIVE" />
+
−
</intent-filter>
+
−
</receiver>
+
−
 
+
−
9.5啟動優惠通知服務
+
−
如果要自動啟動則加在整個程式的進入點(例如:Application 的 onCreate )
+
−
*如欲使用新型態優惠通知服務啟動方式請使用10.2步驟啟動
+
−
 
+
−
 
+
−
關閉優惠通知服務請使用下列程式碼
+
−
 
+
−
9.6可加入按鈕讓使用者開啟個人化優惠通知的設定頁面
+
−
 
+
−
9.7測試優惠通知服務是否成功整合
+
−
 
+
−
如果整合成功將出現測試優惠通知,如下圖所示。
+
−
 
+
−
如果未出現請重新檢查。
+
−
 
+
−
10.新型態優惠通知服務
+
−
10.1AndroidManifest.xml 的 Application 底下加入下列程式碼。
+
−
背景Activity 需填入主畫面Activity,如:”.MainAcitvity” 或 “com.example.ExampleApp”
+
−
 
+
−
10.2啟動優惠通知服務。
+
−
背景Activity 需填入與10.1步驟相同的主畫面Activity,如:MainActivity.class
+
−
 
+
−
*與9.5請擇一使用
+
−
+
−
11.ProGuard
+
−
 
+
−
如需ProGuard 請加入以下設定:
+
−
 
+
−
-keep public class com.adlocus.** {*;}
+
−
-keep class com.adlocus.adapters.AdLocusAdapter$MyJavaScriptInterface{<methods>;}
+
−
 
+
−
 
+
−
== 測試模式 ==
+
−
當您完整 SDK 整合後,您可透過設定下列參數開啟測試模式(測試模式下的互動在平台上將不記錄).
+
−
void setTestMode(boolean isTesting)
+
−
 
+
−
 
+
−
== 觀眾定向(Optional) ==
+
−
透過 AdLocusTargeting 設置您的觀眾參數
+
 
* 年齡
 
* 年齡
 
* 生日
 
* 生日
 +
* 性別
 
* 測試模式
 
* 測試模式
  
Line 223: Line 51:
 
targeting.setBirthDate(new GregorianCalendar(1990, 12, 29));
 
targeting.setBirthDate(new GregorianCalendar(1990, 12, 29));
 
targeting.setGender(AdLocusTargeting$Gender.MALE);  
 
targeting.setGender(AdLocusTargeting$Gender.MALE);  
−
targeting.setTestMode(false);  
+
targeting.setTestMode(true); //使用測試模式
 
</syntaxhighlight>
 
</syntaxhighlight>
  
−
== 開啟定向功能 ==
+
=== 開啟測試/定向 ===
  
−
=== Inapp ===
+
==== InApp ====
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
 
AdLocusLayout adlocusLayout1 =  new AdLocusLayout(this,
 
AdLocusLayout adlocusLayout1 =  new AdLocusLayout(this,
Line 237: Line 65:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
−
=== Push ===  
+
==== Promotion ====
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
−
AdLocusTargeting.enablePush(this, app key, targeting);
+
PushAd.enablePush(this, "your app key", promotionIntent, targeting);
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 10:24, 3 December 2019

Getting Start with AdLocus

以下將說明您怎麼整入 AdLocus SDK.

自我檢查

Android Studio

  • Gradle 中加入AdLocus (Y/N)
  • Tool > Android > Sync Project With Gradle Files (Y/N)

若您已完成上述檢查卻無法正確啟用相關服務, 請來信 support@adlocus.com , 我們將有專人與您聯繫.

取得您的 App Key

  • 至 https://adlocus.com/ 點 <開發商> 申請帳號並登入。
  • 在「應用程式」中「新增」您的應用程式並取得app key。

準備將 SDK 加入到您的專案

InApp

Promotion

Interstitial

Video

AdMob Mediation

測試模式與觀眾定向(Optional)

當您完成 SDK 整合後,您可透過設定下列參數開啟測試模式(測試模式下的互動在平台上將不記錄).

  • 年齡
  • 生日
  • 性別
  • 測試模式
// 設定使用者年齡 (也可使用 setBirthday())
void setAge(int age) 
void setBirthDate(GregorianCalendar birthday))
void setGender(AdLocusTargeting$Gender gender)
void setTestMode(boolean isTesting)
 
// 設置範例:
AdLocusTargeting targeting = new AdLocusTargeting();
targeting.setAge(23); 
targeting.setBirthDate(new GregorianCalendar(1990, 12, 29));
targeting.setGender(AdLocusTargeting$Gender.MALE); 
targeting.setTestMode(true);  //使用測試模式

開啟測試/定向

InApp

AdLocusLayout adlocusLayout1 =  new AdLocusLayout(this,
				AdLocusLayout.AD_SIZE_IAB_MRECT,
				appKey, 
				15,
				targeting);

Promotion

PushAd.enablePush(this, "your app key", promotionIntent, targeting);