Android Beacon DeviceInfo SDK Tutorial

出自TAMedia
於 2017年7月12日 (三) 08:32 由 imported>Wikiuser 所做的修訂
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
跳至導覽 跳至搜尋

Download Android Beacon DeviceInfo SDK

含有Beacon DeviceInfo SDK以及範例程式碼
Version Package Size Notes
1.0.0 twmBeaconDeviceInfoSDK_1.0.0
108 KB
  • Initial release


Getting Started

  • 簡介
AndroidBeacon設備資訊SDK提供Android App開發者取得iBeacon的Mac Address、電量、位置、公司名和相關網址等設備資訊。
  • 系統需求
Android 2.3以上(API 9+)、Java 7以上
  • 開始使用

以Android Studio整合 (Version: 2.3.3)

Step 1: 整合Retrofit
在build.gradle的dependencies內加入下列程式碼:
 compile 'com.squareup.retrofit2:retrofit:2.3.0
 compile 'com.squareup.retrofit2:converter-gson:2.3.0'


Step 2: 整合Android Beacon DeviceInfo SDK
將jar檔放到libs資料夾
Android BeaconInfoSDK AS GTS Step2.png
並在build.gradle的dependencies內加入下列程式碼:
 compile files('libs/twm_beaconinfo_sdk.jar')


Step 3: 在AndroidManifest.xml加入必要權限
打開AndroidManifest.xml
Android BeaconInfoSDK AS GTS Step3.png
並在manifest tag內加入下列程式碼:
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


以Eclipse整合 (Version: Neon.3 Release (4.6.3), Eclipse for Android Developers )

Step 1: 下載Retrofit相關套件
請到下列網址下載各個套件的jar檔
Library URL
Retrofit2
http://square.github.io/retrofit/
Retrofit2-Converter-Gson
https://github.com/square/retrofit/tree/master/retrofit-converters/gson
Google-Gson
https://www.versioneye.com/java/com.google.code.gson:gson/2.8.1
OkHttp3
http://square.github.io/okhttp/
Okio
https://github.com/square/okio


Step 2: 整合Retrofit與Android Beacon DeviceInfo SDK
將6個jar檔放到libs資料夾 (5 for Retrofit, 1 for Beacon DeviceInfo SDK),若無此資料夾可自行建立,Eclipse會自動建立關聯
Android BeaconInfoSDK EP GTS Step2.png


Step 3: 在AndroidManifest.xml加入必要權限
打開AndroidManifest.xml
Android BeaconInfoSDK EP GTS Step3.png
在manifest tag內加入下列程式碼:
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


Documentation

  • 設備資訊請求
請在程式內加入此行,SDK會依據UUID、Major、Minor和Access Token回傳對應的設備資訊
 //請依序傳入UUID, Major, Minor, Access Token, 以及Callback
 TWMBeacon4GSDK.getInstance().getBeaconInfo("<uuid>", "<major>", "<minor>", "<accessToken>", mBeaconInfoCallback);
Callback範例如下:
 private TWMBeacon4GCallback<BeaconInfoResponse> mBeaconInfoCallback = new TWMBeacon4GCallback<BeaconInfoResponse>(){
      @Override
      public void onResponse(BeaconInfoResponse result) {
          BeaconInfo bInfo = result.getBeaconInfo();
          Log.d("MyBeaconLog",
                  "Status Code: " + result.getStatusCode() + "\n" +
                  "Message: " + result.getMessage() + "\n" +
                  "Company: " + bInfo.getCompany() + "\n" +
                  "Tax ID: " + bInfo.getTaxId() + "\n" +
                  "Mac Address: " + bInfo.getMacAddress() + "\n" +
                  "UUID: " + bInfo.getUuid() + "\n" +
                  "Major: " + bInfo.getMajor() + "\n" +
                  "Minor: " + bInfo.getMinor() + "\n" +
                  "Power: " + bInfo.getPower() + "\n" +
                  "Location: " + bInfo.getLocation() + "\n" +
                  "Physical Address: " + bInfo.getPhysicalAddress() + "\n" +
                  "Picture: " + bInfo.getPicture() + "\n" +
                  "URL: " + bInfo.getUrl() + "\n" +
                  "Battery Level: " + bInfo.getBatteryLevel() + "\n" +
                  "Register Date: " + bInfo.getRegisterDate() + "\n" +
                  "Service Date: " + bInfo.getServiceDate() + "\n" +
                  "Maintenance Date: " + bInfo.getMaintenanceDate() + "\n" +
                  "Access Token: " + bInfo.getAccessToken()
          );
      }
 
      @Override
      public void onErrorResponse(TWMRetrofitError error, String message) {
         // Connection Error
         Log.e("MyBeaconLog", message);
      }
  };


Proguard Configuration

如果您的APP本身需要經過proguard混淆,請增加下面的設定
 ##----------- Begin: proguard configuration for TWMBeaconDeviceInfoSDK ---------
 -keep class com.taiwanmobile.pt.beacon4g.** { *; }
 ##---------------End: proguard configuration for TWMBeaconDeviceInfoSDK  ----------
 
 ##----------- Begin: proguard configuration for Retrofit ---------
 -dontnote retrofit2.Platform
 -dontwarn retrofit2.Platform$Java8
 -keepattributes Exceptions
 -keepattributes Signature
 -dontwarn okio.**
 -dontwarn javax.annotation.**
 ##---------------End: proguard configuration for Retrofit  ----------
 
 ##---------------Begin: proguard configuration for Gson  ----------
 -keepattributes Signature
 -keepattributes *Annotation*
 -keep class sun.misc.Unsafe { *; }
 -keep class com.google.gson.examples.android.model.** { *; }
 ##---------------End: proguard configuration for Gson  ----------