「Android BeaconSDK Tutorial」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
(未顯示同一使用者於中間所作的 7 次修訂) | |||
行 1: | 行 1: | ||
*廣告請求 | *廣告請求 | ||
: | :請在您程式開始的Activity加入下列程式碼,以啟動TWMBeaconSDK。啟動成功後SDK會在背景偵測附近是否有Beacon存在,並且依據Beacon的相關資訊進行廣告請求,您不需再做任何額外設定。 | ||
//依序傳入activity , 版位ID , TWMBeaconRequest | |||
TWMBeaconSDK.init(MainActivity.this, 您的版位ID, new TWMBeaconRequest.Builder.build()); | TWMBeaconSDK.init(MainActivity.this, 您的版位ID, new TWMBeaconRequest.Builder.build()); | ||
*TWMBeaconRequest | *TWMBeaconRequest | ||
:: | ::TWMBeaconRequest為請求設定檔,提供的function及說明如下,請依您的需求進行設定。 | ||
:*設定通知列small icon | :*設定通知列small icon | ||
::強烈建議將通知icon設為您希望顯示的icon,若未設定則會以app icon作為替代。 | ::強烈建議將通知icon設為您希望顯示的icon,若未設定則會以app icon作為替代。 | ||
[[檔案:beaconsdk_tutorial_2.png]] | |||
setNotificationIcon(int icon) | setNotificationIcon(int icon) | ||
:*設定掃描模式 | :*設定掃描模式 | ||
:: | ::TWMBeaconSDK提供與原生方法相同的三種掃描模式,預設為LowPower模式。若無特殊需求,建議您不需設定此選項。<br>SCAN_MODE_BALANCED , SCAN_MODE_LOW_LATENCY ,SCAN_MODE_LOW_POWER | ||
setScanMode(ScanMode scanMode) | setScanMode(ScanMode scanMode) | ||
:*設定測試模式 | :*設定測試模式 | ||
::測試模式所有的請求將不會被記錄,傳入的testDevice字串請您參考[[Android_Banner_Ads_I_2.0|Android_Banner_Ads_I_2.0]] | ::測試模式所有的請求將不會被記錄,傳入的testDevice字串請您參考[[Android_Banner_Ads_I_2.0|Android_Banner_Ads_I_2.0]] | ||
行 49: | 行 39: | ||
} | } | ||
}); | }); | ||
*完整範例請參考下列 | *完整範例請參考下列 | ||
:Activity | :*Activity | ||
package com.taiwanmobile.beacontest; | package com.taiwanmobile.beacontest; | ||
import android.content.Intent; | import android.content.Intent; | ||
行 74: | 行 58: | ||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | setContentView(R.layout.activity_main); | ||
//設定TWMBeaconRequest | //設定TWMBeaconRequest | ||
request = new TWMBeaconRequest.Builder() | request = new TWMBeaconRequest.Builder() | ||
//設定通知列icon | //設定通知列icon | ||
.setNotificationIcon(YOUR_ICON) | .setNotificationIcon(YOUR_ICON) | ||
.build(); | .build(); | ||
//啟動TWMBeaconSDK | //啟動TWMBeaconSDK | ||
行 97: | 行 67: | ||
TWMBeaconSDK.setAdListener(new TWMBeaconListener() { | TWMBeaconSDK.setAdListener(new TWMBeaconListener() { | ||
@Override | @Override | ||
public void onReceiveAd() { | public void onReceiveAd() { | ||
} | } | ||
@Override | @Override | ||
行 112: | 行 82: | ||
} | } | ||
}); | }); | ||
} | } | ||
} | } | ||
:Manifest | :*Manifest | ||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
行 146: | 行 110: | ||
</activity> | </activity> | ||
<activity android:name="com.taiwanmobile.beaconsdk.internal.TWMRedirectActivity" | <activity android:name="com.taiwanmobile.beaconsdk.internal.TWMRedirectActivity" | ||
android: | android:taskAffinity="com.taiwanmobile.beaconsdk.internal.TWMBeaconActivity" | ||
android:excludeFromRecents="true"/> | |||
<activity | <activity | ||
android:name="com.taiwanmobile.beaconsdk.internal.TWMBeaconActivity" | android:name="com.taiwanmobile.beaconsdk.internal.TWMBeaconActivity" | ||
android:configChanges="orientation|keyboardHidden|navigation|keyboard|screenLayout|uiMode|screenSize|smallestScreenSize" | android:configChanges="orientation|keyboardHidden|navigation|keyboard|screenLayout|uiMode|screenSize|smallestScreenSize" | ||
android:hardwareAccelerated="true" | android:hardwareAccelerated="true" | ||
android:launchMode=" | android:launchMode="singleTop" | ||
android:taskAffinity="com.taiwanmobile.beaconsdk.internal.TWMBeaconActivity" | |||
android:taskAffinity="" | |||
android:excludeFromRecents="true" | android:excludeFromRecents="true" | ||
android:theme="@android:style/Theme.Translucent"/> | android:theme="@android:style/Theme.Translucent"/> | ||
行 159: | 行 123: | ||
</application> | </application> | ||
</manifest> | </manifest> | ||
*畫面展示 | |||
{| width="50%" border="1" | |||
|- | |||
| align="center" | 插頁全版廣告 | |||
| align="center" | 插頁彈跳文字廣告 | |||
| align="center" | 插頁彈跳圖文廣告 | |||
|- | |||
| align="center" | [[檔案:Beacon_sdk_demo1.png]] | |||
| align="center" | [[檔案:Beacon_sdk_demo2.png]] | |||
| align="center" | [[檔案:Beacon_sdk_demo3.png]] | |||
|} |
於 2017年2月20日 (一) 07:30 的最新修訂
- 廣告請求
- 請在您程式開始的Activity加入下列程式碼,以啟動TWMBeaconSDK。啟動成功後SDK會在背景偵測附近是否有Beacon存在,並且依據Beacon的相關資訊進行廣告請求,您不需再做任何額外設定。
//依序傳入activity , 版位ID , TWMBeaconRequest TWMBeaconSDK.init(MainActivity.this, 您的版位ID, new TWMBeaconRequest.Builder.build());
- TWMBeaconRequest
- TWMBeaconRequest為請求設定檔,提供的function及說明如下,請依您的需求進行設定。
- 設定通知列small icon
- 強烈建議將通知icon設為您希望顯示的icon,若未設定則會以app icon作為替代。
setNotificationIcon(int icon)
- 設定掃描模式
- TWMBeaconSDK提供與原生方法相同的三種掃描模式,預設為LowPower模式。若無特殊需求,建議您不需設定此選項。
SCAN_MODE_BALANCED , SCAN_MODE_LOW_LATENCY ,SCAN_MODE_LOW_POWER
setScanMode(ScanMode scanMode)
- 設定測試模式
- 測試模式所有的請求將不會被記錄,傳入的testDevice字串請您參考Android_Banner_Ads_I_2.0
addTestDevice(String testDevice) setTestDevices(Set<String> testDevices)
- 加入TWMBeaconListener監聽廣告投放情況
TWMBeaconSDK.setAdListener(new TWMBeaconListener() { @Override public void onReceiveAd() { // 成功收到廣告時通知 } @Override public void onFailedToReceiveAd(TWMBeaconRequest.ErrorCode errorCode) { // 當請求廣告失敗時通知 } @Override public void onPresentScreen() { // 廣告呈現在頁面時通知 } @Override public void onDismissScreen() { // 關閉廣告時通知 } @Override public void onFailedStart (String errorMessage) { // 無法成功開啟服務時通知 } });
- 完整範例請參考下列
- Activity
package com.taiwanmobile.beacontest; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.view.View; import com.taiwanmobile.beaconsdk.settings.BluetoothDialogSettings; import com.taiwanmobile.beaconsdk.internal.TWMBeaconRequest; import com.taiwanmobile.beaconsdk.internal.TWMBeaconListener; import com.taiwanmobile.beaconsdk.internal.TWMBeaconSDK; import com.taiwanmobile.beaconsdk.service.TWMBeaconService; public class MainActivity extends AppCompatActivity { TWMBeaconRequest request; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //設定TWMBeaconRequest request = new TWMBeaconRequest.Builder() //設定通知列icon .setNotificationIcon(YOUR_ICON) .build(); //啟動TWMBeaconSDK TWMBeaconSDK.init(MainActivity.this, "您的版位ID", request); TWMBeaconSDK.setAdListener(new TWMBeaconListener() { @Override public void onReceiveAd() { } @Override public void onFailedToReceiveAd(TWMBeaconRequest.ErrorCode errorCode) { } @Override public void onFailedStart(String errorMessage) { } @Override public void onPresentScreen() { } @Override public void onDismissScreen() { } }); } }
- Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.taiwanmobile.beacontest"> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <application android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.taiwanmobile.beaconsdk.internal.TWMRedirectActivity" android:taskAffinity="com.taiwanmobile.beaconsdk.internal.TWMBeaconActivity" android:excludeFromRecents="true"/> <activity android:name="com.taiwanmobile.beaconsdk.internal.TWMBeaconActivity" android:configChanges="orientation|keyboardHidden|navigation|keyboard|screenLayout|uiMode|screenSize|smallestScreenSize" android:hardwareAccelerated="true" android:launchMode="singleTop" android:taskAffinity="com.taiwanmobile.beaconsdk.internal.TWMBeaconActivity" android:excludeFromRecents="true" android:theme="@android:style/Theme.Translucent"/> <service android:name="com.taiwanmobile.beaconsdk.service.TWMBeaconService" /> </application> </manifest>
- 畫面展示
插頁全版廣告 | 插頁彈跳文字廣告 | 插頁彈跳圖文廣告 |