「Android BeaconSDK Tutorial」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
行 10: | 行 10: | ||
[[檔案:beaconsdk_tutorial_1.png]] | [[檔案:beaconsdk_tutorial_1.png]] | ||
BluetoothDialogSettings settings = new BluetoothDialogSettings(); | BluetoothDialogSettings settings = new BluetoothDialogSettings(); | ||
settings.setMessage(" | settings.setMessage("您所希望顯示的Message"); | ||
settings.setTitle(" | settings.setTitle("您所希望顯示的Title"); | ||
settings.setNegativeButtonText(" | settings.setNegativeButtonText("您所希望顯示的NegativeButton"); | ||
settings.setPositiveButtonText(" | settings.setPositiveButtonText("您所希望顯示的PositiveButton"); | ||
:*設定通知列small icon | :*設定通知列small icon | ||
::強烈建議將通知icon設為您希望顯示的icon,若未設定則會以app icon作為替代。 | ::強烈建議將通知icon設為您希望顯示的icon,若未設定則會以app icon作為替代。 | ||
行 75: | 行 75: | ||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | setContentView(R.layout.activity_main); | ||
//設定要求開啟藍芽提醒文字 | //設定要求開啟藍芽提醒文字, 請將此處設為您想要的文字, 若不需變更請忽略此段設定 | ||
BluetoothDialogSettings settings = new BluetoothDialogSettings(); | BluetoothDialogSettings settings = new BluetoothDialogSettings(); | ||
settings.setMessage("Message"); | settings.setMessage("Message"); |
於 2016年11月2日 (三) 02:35 的修訂
- 廣告請求
- 請在您程式開始的Activity加入下列程式碼,以啟動TWMBeaconSDK。啟動成功後SDK會在背景偵測附近是否有Beacon存在,並且依據Beacon的相關資訊進行廣告請求,您不需再做任何額外設定。
//依序傳入activity , 版位ID , TWMBeaconRequest TWMBeaconSDK.init(MainActivity.this, 您的版位ID, new TWMBeaconRequest.Builder.build());
- TWMBeaconRequest
- TWMBeaconRequest為請求設定檔,提供的function及說明如下,請依您的需求進行設定。
- 設定要求使用者開啟藍芽之文字
setBluetoothDialogSettings(BluetoothDialogSettings settings)
- 您可以針對Title、Message、positive button以及negative button設定您想要顯示的文字,預設文字如下圖所示,您可以不變更此設定。
BluetoothDialogSettings settings = new BluetoothDialogSettings(); settings.setMessage("您所希望顯示的Message"); settings.setTitle("您所希望顯示的Title"); settings.setNegativeButtonText("您所希望顯示的NegativeButton"); settings.setPositiveButtonText("您所希望顯示的PositiveButton");
- 設定通知列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)
- 設定要求使用者開啟權限(ACCESS_COARSE_LOCATION)之文字(6.0以上需要)
- 此方法與setBluetoothDialogSettings類似,請參考上述說明。
- 設定測試模式
- 測試模式所有的請求將不會被記錄,傳入的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) { // 無法成功開啟服務時通知 } });
- Android 6.0 Runtime Permissions
- 如果您的應用程式target版本為Android 6.0以上,由於權限的問題,請您在啟動TWMBeaconSDK的activity override onRequestPermissionsResult function
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { TWMBeaconSDK.onRequestPermissionsResult( requestCode, permissions, grantResults); }
- 完整範例請參考下列
- 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); //設定要求開啟藍芽提醒文字, 請將此處設為您想要的文字, 若不需變更請忽略此段設定 BluetoothDialogSettings settings = new BluetoothDialogSettings(); settings.setMessage("Message"); settings.setTitle("Title"); settings.setNegativeButtonText("NegativeButton"); settings.setPositiveButtonText("PositiveButton"); //設定TWMBeaconRequest request = new TWMBeaconRequest.Builder() //設定通知列icon .setNotificationIcon(YOUR_ICON) .setBluetoothDialogSettings(settings) .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() { } }); } //6.0動態權限必須 @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { TWMBeaconSDK.onRequestPermissionsResult( requestCode, permissions, grantResults); } }
- 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>
- 畫面展示
插頁全版廣告 | 插頁彈跳文字廣告 | 插頁彈跳圖文廣告 |