Language
JavaIndexes
- 利用要件Requirements
- 依存ライブラリDependencies
- 導入手順How to install
- その他Miscellaneous
利用要件Requirements
▲ Indexes- Android Studio Ladybug Feature Drop | 2024.2.2 以降 推奨or higher (Recommended)
- Gradle Plugin 8.4.2 以降 推奨or higher (Recommended)
- Gradle 8.6 以降 推奨or higher (Recommended)
- Compile SDK Version 34 (Android 14) 以降 推奨or higher (Recommended)
- Android SDK Build Tools 34.0.0 以降 推奨or higher (Recommended)
- Minimum API Level ... 23 (Android 6.0)
- Target API Level ... 33 (Android 13)
- JDK Version ... 11
- Permissions
android.permission.INTERNET
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.ACCESS_COARSE_LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.FOREGROUND_SERVICE
(Android 9 以降の場合に必須Essential for Android 9 or higher)android.permission.ACCESS_BACKGROUND_LOCATION
(Android 10 以降の場合のみOnly for Android 10 or higher)android.permission.BLUETOOTH_SCAN
(Android 12 以降の場合に必須Essential for Android 12 or higher)com.google.android.gms.permission.AD_ID
(Android 12 以降の場合に必須Essential for Android 12 or higher)android.permission.POST_NOTIFICATIONS
(Android 13 以降かつ、プッシュ通知を利用する場合に必要Required for Android 13 or higher and for using push notifications)
app/build.gradle
android {
defaultConfig {
compileSdk 34
buildToolsVersion = '34.0.0'
minSdkVersion 23
targetSdkVersion 33
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
AndroidManifest.xml
位置情報へのアクセス許可をアプリの使用中のみにする場合、 <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- AIBeacon: Android 9 以降の場合に必要なパーミンション -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- AIBeacon: Android 10 以降の場合に必要なパーミンション -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- AIBeacon: Android 12 以降の場合に必要なパーミンション -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<!-- AIBeacon: Android 13 以降かつ、プッシュ通知を利用する場合に必要なパーミンション -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
ACCESS_BACKGROUND_LOCATION
パーミッションは必要ありません。※ 不要な場合は tools:node="remove" を付けて、マニフェストからこの要素を削除します。
AndroidManifest.xml
※ ただし、位置情報へのアクセス許可をアプリの使用中のみにした場合は、アプリがバックグラウンド状態で AIBeacon を検知できなくなります。Android 11 以降で <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" tools:node="remove" />
ACCESS_BACKGROUND_LOCATION
パーミッションが設定されている場合、アクセス許可を求めるシステムダイアログに [常に許可]
は表示されませんので、下記を参考にアプリの設定ページで位置情報へのアクセスを [常に許可]
に設定するよう促す説明 UI を表示するようにして下さい。https://developer.android.com/preview/privacy/location?hl=ja#background-location
AndroidManifest.xml
You don't need <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- AIBeacon: Essential permissions for Android 9 or higher -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- AIBeacon: Essential permissions for Android 10 or higher -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<!-- AIBeacon: Essential permissions for Android 12 or higher -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<!-- AIBeacon: Required permissions for Android 13 or higher and for using push notifications -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
ACCESS_BACKGROUND_LOCATION
permission if you want to allow access to your location only while using app.※ If you don't need it, remove this element from your manifest with tools:node="remove".
AndroidManifest.xml
* Remark that your app cannot detect AIBeacon in background if you want to allow access to your location only while using the app.If <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" tools:node="remove" />
ACCESS_BACKGROUND_LOCATION
permission is set on Android 11 or higher, [Allow all the time]
is not displayed in the system dialog for permission, so refer to the following and display the explanation UI that prompts you to set access to location information to [Allow all the time]
on the setting page of the app.https://developer.android.com/training/location/permissions?hl=en#request-background-location
依存ライブラリDependencies
▲ IndexesGoogle Play Services (v9.0.1+)
プロジェクトに Google Play Services (バージョン 9.0.1 以降) を追加します。
build.gradle
の allprojects
> repositories {}
ブロック及び、 app/build.gradle
の dependencies {}
ブロック内に下記の内容を追加します。Add Google Play Services (Version 9.0.1 or higher) to your project.
Add the following content into
Add the following content into
allprojects
> repositories {}
block of build.gradle
and dependencies {}
block of app/build.gradle
.build.gradle
allprojects {
repositories {
google()
}
}
app/build.gradle
dependencies {
implementation 'com.google.android.gms:play-services-ads-identifier:17.1.0'
}
次に、
AndroidManifest.xml
の <application>
エレメント内に、 Google Play Services のバージョンを設定します。Next, set the version of Google Play Services into the
<application>
element of your AndroidManifest.xml
.AndroidManifest.xml
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
AndroidX
プロジェクトに AndroidX を追加します。
Add AndroidX to your project.
build.gradle
ファイルのリポジトリに google()
を追加します。Add
google()
to the repository in your build.gradle
file.build.gradle
allprojects {
repositories {
google()
}
}
gradle.properties
ファイルで以下の 2 つのフラグを true
に設定します。Set the following two flags to
true
in your gradle.properties
file:gradle.properties
android.enableJetifier=true
android.useAndroidX=true
※ AndroidX を使用するために既存のサードパーティライブラリを移行する必要がない場合や、他のサードパーティライブラリを使用していない場合は
参考 URL: https://developer.android.com/jetpack/androidx/?hl=ja
android.enableJetifier
を false
に設定できます。参考 URL: https://developer.android.com/jetpack/androidx/?hl=ja
* You can set
refs: https://developer.android.com/jetpack/androidx/?hl=en
android.enableJetifier
to false
if you do not need to migrate your existing third party libraries to use AndroidX, or you are not using any other third party libraries.refs: https://developer.android.com/jetpack/androidx/?hl=en
app/build.gradle
ファイルの依存関係に以下を追加します。Add the following to the dependency in your
app/build.gradle
file:app/build.gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.core:core:1.13.1'
implementation 'androidx.security:security-crypto:1.0.0'
}
※ 従来の Support Library から AndroidX へ移行する場合は下記を参照下さい。
https://developer.android.com/jetpack/androidx/migrate?hl=ja
https://developer.android.com/jetpack/androidx/migrate?hl=ja
* Please refer to the following when migrating from the original support library to AndroidX:
https://developer.android.com/jetpack/androidx/migrate?hl=en
https://developer.android.com/jetpack/androidx/migrate?hl=en
導入手順How to install
▲ Indexes基本設定Basic setting
AIBeaconSDK.jar を導入Install AIBeaconSDK.jar
プロジェクトに
AIBeaconSDK.jar
を追加します。AIBeaconSDK.jar
を app/libs/
に配置し、 app/build.gradle
の dependencies {}
ブロック内に下記の内容を追加します。Add
Place
AIBeaconSDK.jar
to you project.Place
AIBeaconSDK.jar
at app/libs/
and add the following content into dependencies {}
block of app/build.gradle
.app/build.gradle
implementation files('libs/AIBeaconSDK.jar')
または、
or
app/build.gradle
implementation fileTree(dir: 'libs', include: ['AIBeaconSDK.jar'])
下記のような指定が既にある場合は、新たに追加する必要はありません。
You don't need to add anything if your
dependencies {}
block has a line like this.app/build.gradle
implementation fileTree(dir: 'libs', include: ['*.jar'])
次に、
AIBeaconService
を登録します。AndroidManifest.xml
の <application>
要素内に jp.co.adinte.AIBeaconSDK.AIBeaconService
を追加します。Next, register
Set
AIBeaconService
.Set
jp.co.adinte.AIBeaconSDK.AIBeaconService
into the <application>
element of your AndroidManifest.xml
.AndroidManifest.xml
<service
android:name="jp.co.adinte.AIBeaconSDK.AIBeaconService"
android:exported="false" >
</service>
次に、
AIBeaconReceiver
を登録します。AndroidManifest.xml
の <application>
要素内に jp.co.adinte.AIBeaconSDK.AIBeaconReceiver
を追加します。Next, register
Set
AIBeaconReceiver
.Set
jp.co.adinte.AIBeaconSDK.AIBeaconReceiver
into the <application>
element of your AndroidManifest.xml
.AndroidManifest.xml
<receiver android:name="jp.co.adinte.AIBeaconSDK.AIBeaconReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
</intent-filter>
</receiver>
AIBeaconSDK
を利用する各ファイルに jp.co.adinte.AIBeaconSDK
をインポートします。Import
jp.co.adinte.AIBeaconSDK
to your file and use AIBeaconSDK
in it.MyClass.java
import jp.co.adinte.AIBeaconSDK.*;
ProGuard の設定Settings for ProGuard
app/build.gradle
の minifyEnabled
を true
に設定する場合は、 ProGuard のルールに下記の内容を追加します。If you want to set
minifyEnabled
in app/build.gradle
to true
, add the following rules to ProGuard rules file.proguard-rules.pro
-keep class jp.co.adinte.AIBeaconSDK.** { *; }
-keep class androidx.core.app.** { *; }
Android 7.0 以降で利用する場合If you use on Android 7.0 or higher
targetSdkVersion
が Android 7.0 (API level 24) 以降の場合は、 AIBeaconJobService
を登録します。AndroidManifest.xml
の <application>
要素内に jp.co.adinte.AIBeaconSDK.AIBeaconJobService
を追加します。Register
Set
AIBeaconJobService
if the targetSdkVersion
is Android 7.0 (API level 24) or higher.Set
jp.co.adinte.AIBeaconSDK.AIBeaconJobService
into the <application>
element of your AndroidManifest.xml
.AndroidManifest.xml
<service
android:name="jp.co.adinte.AIBeaconSDK.AIBeaconJobService"
android:permission="android.permission.BIND_JOB_SERVICE">
</service>
SDK 利用設定Settings for AIBeaconSDK
AIBeaconApplication のセットアップSetup AIBeaconApplication
AndroidManifest.xml
に AIBeaconApplication
を登録します。<application>
要素に android:name
属性を追加し以下のように記述します。You need to register
Add the
AIBeaconApplication
to AndroidManifest.xml
.Add the
android:name
property into the <application>
element and set the value as follows.AndroidManifest.xml
<application
android:name="jp.co.adinte.AIBeaconSDK.AIBeaconApplication"
... >
既に
Application
クラスを継承した独自クラスを実装している場合は、その独自クラスが AIBeaconApplication
を継承するように書き換えて下さい。If you have already implemented your own class inherited from the
Application
class, you need to modify your class to be inherited from AIBeaconApplication
.MyApplication.java
public class MyApplication extends AIBeaconApplication {
...
}
Multidex
サポートで android.support.multidex.MultiDexApplication
を利用している場合は、attachBaseContext()
メソッドをオーバーライドし、MultiDex.install(this)
で Multidex
を有効します。参考 URL: https://developer.android.com/studio/build/multidex.html?hl=ja
In the case where you use
you need to override the
refs: https://developer.android.com/studio/build/multidex.html?hl=en
android.support.multidex.MultiDexApplication
for Multidex support,you need to override the
attachBaseContext()
method to call MultiDex.install(this)
and enable Multidex
.refs: https://developer.android.com/studio/build/multidex.html?hl=en
MyApplication.java
public class MyApplication extends AIBeaconApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
...
}
独自クラスが
AIBeaconApplication
を継承できない場合は、以下の実装を行って下さい。If you cannot inherit your own class from
AIBeaconApplication
, implement as follows.MyApplication.java
public class MyApplication extends OtherApplication {
@Override
public void onCreate() {
super.onCreate();
// AIBeaconApplication をセットアップする。
AIBeaconApplication.setup(this);
}
...
}
MyApplication.java
public class MyApplication extends OtherApplication {
@Override
public void onCreate() {
super.onCreate();
// Setup AIBeaconApplication.
AIBeaconApplication.setup(this);
}
...
}
AIBeaconManager の初期化Initializing AIBeaconManager
SDK 利用にあたり、先ずは
アプリ情報は AIBeaconSDK 配布サイト > App Info からご確認いただけます。
AIBeaconManager
の初期化を行います。[Your App ID]
、 [Your API Key]
のアプリ情報には、弊社から提供する値を設定します。アプリ情報は AIBeaconSDK 配布サイト > App Info からご確認いただけます。
To use the SDK, you need to initialize
Set the values we provided to app information of
App information can be found at the AIBeaconSDK distribution site > App Info.
AIBeaconManager
first.Set the values we provided to app information of
[Your App ID]
, and [Your API Key]
.App information can be found at the AIBeaconSDK distribution site > App Info.
MyActivity.java
AIBeaconManager aiBeaconManager = AIBeaconManager.init(this, "[Your App ID]", "[Your API Key]");
AIBeacon サービスへの登録Registration to AIBeacon Service
AIBeaconManager
の初期化が終わったら、次は AIBeacon サービスへの登録処理を行います。自動サービス登録 (
AIBeaconManagerInitOption.Keys.AutoServiceRegistrationEnabled
) を有効にしている場合は、登録処理が自動で行われるので下記の実装は必要ありません。After initializing
If you enable auto registration of the service (
AIBeaconManager
, you need to register to AIBeacon service.If you enable auto registration of the service (
AIBeaconManagerInitOption.Keys.AutoServiceRegistrationEnabled
), you don't need the following implementation because the registration is automated.MyActivity.java
AIBeaconManager.sharedInstance().registerService();
AIBeacon のモニタリング開始Start monitoring AIBeacon
startAiBeaconMonitoring()
を呼び出して AIBeacon のモニタリングを開始します。Call
startAiBeaconMonitoring()
and start monitoring of AIBeacon.MyActivity.java
AIBeaconManager.sharedInstance().startAiBeaconMonitoring();
AIBeacon サービスの利用に必要なパーミッションの許可要求処理を実装する必要があります。
startAiBeaconMonitoring()
を呼び出すことで、必要なパーミッションの許可を求めるダイアログが表示されます。Activity
に下記の実装を行い、パーミッションが許可された際に再度 startAiBeaconMonitoring()
を呼び出して AIBeacon の監視処理を開始してください。You need to implement a request procedure for necessary permissions to use the AIBeacon service.
You can let the device show a dialog to make a request for the necessary permission by calling
Implement the following procedure in Activity and call
You can let the device show a dialog to make a request for the necessary permission by calling
startAiBeaconMonitoring()
.Implement the following procedure in Activity and call
startAiBeaconMonitoring()
again when the permission is granted and start monitoring AIBeacon.MyActivity.java
// 要求されたパーミッションの許可結果を受け取った際に呼び出されます。
@Override
public void onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults
) {
if (requestCode == AIBeaconPermissionsRequestCode.AIBeaconScan) {
if (AIBeaconManager.checkPermissionsGranted(
AIBeaconPermissionsRequestCode.AIBeaconScan, permissions, grantResults
)) {
// AIBeacon の領域監視を開始する。
AIBeaconManager.sharedInstance().startAiBeaconMonitoring();
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
MyActivity.java
// Called when the result of the permission request.
@Override
public void onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults
) {
if (requestCode == AIBeaconPermissionsRequestCode.AIBeaconScan) {
if (AIBeaconManager.checkPermissionsGranted(
AIBeaconPermissionsRequestCode.AIBeaconScan, permissions, grantResults
)) {
// Starts monitoring the region of AIBeacon.
AIBeaconManager.sharedInstance().startAiBeaconMonitoring();
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
パーミッション要求の結果を ActivityResultLauncher で受け取る場合は、代わりに以下を実装してください。
MyActivity.java
// パーミッション要求結果受け取り用の ActivityResultLauncher を設定します。
ActivityResultLauncher<String[]> requestPermissionsResultLauncher = registerForActivityResult(
new ActivityResultContracts.RequestMultiplePermissions(),
results -> {
String[] permissions = results.keySet().toArray(new String[0]);
Boolean[] grantResults = results.values().toArray(new Boolean[0]);
if (AIBeaconManager.checkPermissionsGranted(
AIBeaconPermissionsRequestCode.AIBeaconScan, permissions, grantResults
)) {
// AIBeacon の領域監視を開始する。
AIBeaconManager.sharedInstance().startAiBeaconMonitoring();
}
}
);
...
// AIBeaconManager 初期化後に下記を実装します。
aiBeaconManager.setRequestPermissionsResultLauncher(requestPermissionsResultLauncher);
If you want to receive the result of a permission request in an ActivityResultLauncher, implement the following instead.
MyActivity.java
// Set up an ActivityResultLauncher to receive the results of a permission request.
ActivityResultLauncher<String[]> requestPermissionsResultLauncher = registerForActivityResult(
new ActivityResultContracts.RequestMultiplePermissions(),
results -> {
String[] permissions = results.keySet().toArray(new String[0]);
Boolean[] grantResults = results.values().toArray(new Boolean[0]);
if (AIBeaconManager.checkPermissionsGranted(
AIBeaconPermissionsRequestCode.AIBeaconScan, permissions, grantResults
)) {
// Starts monitoring the region of AIBeacon.
AIBeaconManager.sharedInstance().startAiBeaconMonitoring();
}
}
);
...
// Implement the following after initializing AIBeaconManager.
aiBeaconManager.setRequestPermissionsResultLauncher(requestPermissionsResultLauncher);
プッシュ通知設定Settings for push notification
※ AIBeacon のプッシュ通知機能を利用する場合は以下の手順が必要です。
* You need the following procedure to enable the push notification of AIBeacon.
FCM の設定Settings for FCM
※ 即時/予約プッシュ通知 (リモートプッシュ通知) は利用されず、接触プッシュ通知 (ローカルプッシュ通知) のみを利用される場合、FCM の設定 は不要なので、この手順は飛ばして 共通設定 手順へお進み下さい。Firebase コンソール にアクセスし、 [プロジェクトを追加] から Firebase プロジェクトを作成します。
プロジェクト作成後、 [プロジェクトの設定] から [サービス アカウント] タブを選択し、 [新しい秘密鍵を生成] から生成した秘密鍵 (JSON ファイル) を弊社にご連携下さい。
(弊社で AIBeacon コンソール への登録作業を行います)
※ 2024年6月20日に FCM レガシー API が廃止となったため、サーバーキーはご利用できなくなりました。
プロジェクト作成後、 [プロジェクトの設定] から [サービス アカウント] タブを選択し、 [新しい秘密鍵を生成] から生成した秘密鍵 (JSON ファイル) を弊社にご連携下さい。
(弊社で AIBeacon コンソール への登録作業を行います)
※ 2024年6月20日に FCM レガシー API が廃止となったため、サーバーキーはご利用できなくなりました。
* If you don't use immediate / reserved push notifications (remote push notifications) and only contact push notifications (local push notifications), you don't need to "Settings for FCM", so skip this step and proceed to procedure "Common setting".Go to the Firebase console and create a Firebase project from [Add project].
After creating the project, from [Project settings] , select the [Service accounts] tab, and click [Generate new private key] to generate a private key (JSON file) and send it to us.
(We will register to the AIBeacon Console)
* As FCM Legacy API will be discontinued on June 20, 2024, server keys will no longer be available.
After creating the project, from [Project settings] , select the [Service accounts] tab, and click [Generate new private key] to generate a private key (JSON file) and send it to us.
(We will register to the AIBeacon Console)
* As FCM Legacy API will be discontinued on June 20, 2024, server keys will no longer be available.
<project>/<app-module>/
以下に構成ファイル google-services.json
を配置します。構成ファイルは Firebase コンソール の対象のプロジェクト設定からダウンロードすることができます。
(構成ファイルのダウンロード方法は こちら を参照下さい)
Place the configuration file
The configuration file can be downloaded from the target project settings of the Firebase console.
(Please refer here for the download method of the configuration file)
google-services.json
in the <project>/<app-module>/
directory.The configuration file can be downloaded from the target project settings of the Firebase console.
(Please refer here for the download method of the configuration file)
<project>/build.gradle
及び、 <project>/<app-module>/build.gradle
を次のように編集します。Edit
<project>/build.gradle
and <project>/<app-module>/build.gradle
as follows:build.gradle
buildscript {
dependencies {
// ADD THIS
classpath 'com.google.gms:google-services:4.3.3'
}
}
app/build.gradle
dependencies {
// ADD THIS
implementation 'com.google.firebase:firebase-core:19.0.1'
implementation 'com.google.firebase:firebase-iid:21.1.0'
implementation 'com.google.firebase:firebase-messaging:22.0.0'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
※
firebase-messaging
はバージョン 17.1.0 以降をご利用ください。* Please use
firebase-messaging
version 17.1.0 or higher.AndroidManifest.xml
に jp.co.adinte.AIBeaconSDK.AIFirebaseMessagingService
を追加します。Add
jp.co.adinte.AIBeaconSDK.AIFirebaseMessagingService
to AndroidManifest.xml
.AndroidManifest.xml
<service
android:name="jp.co.adinte.AIBeaconSDK.AIFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
共通設定Common setting
プッシュ通知の詳細内容を表示する為の Service 及び Activity を追加します。
AndroidManifest.xml
の <application>
エレメント内に下記の内容を追加します。Add Service and Activity for showing the detail content of the push notification.
Add the following content into the
Add the following content into the
<application>
element of AndroidManifest.xml
.AndroidManifest.xml
<service
android:name="jp.co.adinte.AIBeaconSDK.AINotificationService"
android:exported="false" >
</service>
<activity
android:name="jp.co.adinte.AIBeaconSDK.AINotificationWindow"
android:theme="@style/AIBeacon.AINotificationWindow" />
次に、
jp.co.adinte.AIBeaconSDK.AINotificationWindow
のスタイルを定義します。res/values/
に任意のスタイル XML を作成するか、既に存在するスタイル XML (styles.xml
など) に下記の内容を追加します。Next, you need to define the style of
Add the following content to new style XML or already existing style XML (
jp.co.adinte.AIBeaconSDK.AINotificationWindow
.Add the following content to new style XML or already existing style XML (
styles.xml
, for example) in res/values/
.styles.xml
<style name="AIBeacon.AINotificationWindow" parent="AppTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
次に、必要なパーミッションを追加します。
AndroidManifest.xml
に下記の内容を追加します。Next, you need to grant necessary permissions.
Add the following content into
Add the following content into
AndroidManifest.xml
.AndroidManifest.xml
<uses-permission android:name="android.permission.VIBRATE" />
次に、 AIBeacon のプッシュ通知機能を有効にします。
PushNotificationEnabled
オプション、もしくは setPushNotificationEnabled(boolean)
メソッドを利用してプッシュ通知機能を有効にします。Next, enable the push notification of AIBeacon.
Enable the push notification of AIBeacon by using
Enable the push notification of AIBeacon by using
PushNotificationEnabled
option of setPushNotificationEnabled(boolean)
method.MyActivity.java
Map<String, Object> options = new HashMap<String, Object>() {{
put(AIBeaconManagerInitOption.Keys.PushNotificationEnabled, new Boolean(true));
}};
AIBeaconManager aiBeaconManager = AIBeaconManager.init(this, "[Your App ID]", "[Your API Key]", options);
// or
AIBeaconManager.sharedInstance().setPushNotificationEnabled(true);
次に、 AIBeacon サービスへの FCM 登録トークン 登録処理を実装します。
自動サービス登録 (
自動サービス登録 (
AutoServiceRegistrationEnabled
オプション) が有効の場合は、 FCM 登録トークン の登録処理が自動で行われるので下記の実装は必要ありません。registerService()
メソッドを呼び出し、 FCM 登録トークン を自動で取得して登録します。Next, you need to implement the registration procedure of FCM registration token of the AIBeacon service.
If you enable the auto service registration (
Call the
If you enable the auto service registration (
AutoServiceRegistrationEnabled
option), the registration procedure of FCM registration token is automated and you don't need the following implementation.Call the
registerService()
method and get FCM registration token automatically and register it.MyActivity.java
AIBeaconManager.sharedInstance().registerService();
次に、通知バーに表示するアイコンのリソース ID を設定します。
※ アイコンが設定されていない場合、通知を受信しても通知バーに表示さませんので必ず設定して下さい。
setNotificationSmallIconId(int)
を利用します。※ アイコンが設定されていない場合、通知を受信しても通知バーに表示さませんので必ず設定して下さい。
Next, you need to set the resource id of the icon to show in the notification bar.
Use
* If the icon is not set, nothing shows in the notification bar even if the notification is received. You should set it.
Use
setNotificationSmallIconId(int)
.* If the icon is not set, nothing shows in the notification bar even if the notification is received. You should set it.
MyActivity.java
AIBeaconManager.sharedInstance().setNotificationSmallIconId(R.drawable.notification_small_icon);
次に、通知をタップした際に起動する Activity のアクティビティ名を設定します。
setNotificationOpenActivityName(String)
を利用します。Next, you need to configure the name of Activity which starts when the notification is tapped.
Use
Use
setNotificationOpenActivityName(String)
.MyActivity.java
AIBeaconManager.sharedInstance().setNotificationOpenActivityName(this.getClass().getName());
Android 12 以降で利用する場合Android 12 以降のデバイスで、通知トランポリンの制限により通知センターの通知をタップした際にアプリが起動しない問題があり、それを回避するために下記の実装が必要になります。通知センターの通知から起動する Activity の onResume で
詳細については
AIBeaconManager.onResume(Intent intent)
を呼び出します。詳細については
AIBeaconManager.onResume(Intent intent)
を参照下さい。If you use on Android 12 or aboveOn devices with Android 12 or later, there is an issue where the app does not launch when you tap a notification in the notification center due to a notification trampoline restriction. To avoid this, the following implementation is required.Call
For details, see
AIBeaconManager.onResume(Intent intent)
in onResume of the Activity launched from the notification in the Notification Center.For details, see
onResume(Intent intent)
.MyActivity.java
@Override
protected void onResume() {
super.onResume();
AIBeaconManager.sharedInstance().onResume(getIntent());
}
その他Miscellaneous
▲ IndexesAPI の詳細については API リファレンス を参照下さい。
Refer the API reference for the details of the API.