Engagelabチャネル統合ガイド
アプリケーション情報の取得
コンソールでアプリケーションを作成します。アプリケーションの作成後、自動的にAppKeyが生成され、アプリケーションを識別するために使用されます。詳細については、アプリケーション設定を参照してください。
ライブラリのインポート
- 手動方法
libsフォルダーからmt-sdk-x.x.x.aarをlibsディレクトリにインポートします。
libsパッケージの下にあるth-xxx-x.x.x.aarをlibsディレクトリにインポートします。
libsフォルダーからmt-sdk-x.x.x.aarをlibsディレクトリにインポートします。
libsパッケージの下にあるth-xxx-x.x.x.aarをlibsディレクトリにインポートします。
このコードブロックはフローティングウィンドウ内に表示されます
- 自動方法
Groovy (build.gradle):
dependencies {
// 必須:メインパッケージ
implementation 'com.engagelab:engagelab:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:Googleベンダー
implementation 'com.engagelab.plugin:google:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:栄耀ベンダー
implementation 'com.engagelab.plugin:honor:5.3.0' // ここではバージョン5.3.0を例として使用しています。
implementation 'com.engagelab.plugin:honor_th_push:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:華為ベンダー
implementation 'com.engagelab.plugin:huawei:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:小米ベンダー(中国版)
implementation 'com.engagelab.plugin:mi:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:魅族ベンダー
implementation 'com.engagelab.plugin:meizu:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// 魅族ベンダー:SDK 5.2.0以降、魅族を統合するには「com.engagelab.plugin:meizu_th_push」が必要です。5.2.0より前は不要です。
implementation 'com.engagelab.plugin:meizu_th_push:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:OPPOベンダー
implementation 'com.engagelab.plugin:oppo:5.3.0' // ここではバージョン5.3.0を例として使用しています。
implementation 'com.engagelab.plugin:oppo_th_push:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:vivoベンダー
implementation 'com.engagelab.plugin:vivo:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:音声ブロードキャスト機能
implementation 'com.engagelab.plugin:oth_sound:5.3.0' // ここではバージョン5.3.0を例として使用しています。
}
dependencies {
// 必須:メインパッケージ
implementation 'com.engagelab:engagelab:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:Googleベンダー
implementation 'com.engagelab.plugin:google:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:栄耀ベンダー
implementation 'com.engagelab.plugin:honor:5.3.0' // ここではバージョン5.3.0を例として使用しています。
implementation 'com.engagelab.plugin:honor_th_push:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:華為ベンダー
implementation 'com.engagelab.plugin:huawei:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:小米ベンダー(中国版)
implementation 'com.engagelab.plugin:mi:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:魅族ベンダー
implementation 'com.engagelab.plugin:meizu:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// 魅族ベンダー:SDK 5.2.0以降、魅族を統合するには「com.engagelab.plugin:meizu_th_push」が必要です。5.2.0より前は不要です。
implementation 'com.engagelab.plugin:meizu_th_push:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:OPPOベンダー
implementation 'com.engagelab.plugin:oppo:5.3.0' // ここではバージョン5.3.0を例として使用しています。
implementation 'com.engagelab.plugin:oppo_th_push:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:vivoベンダー
implementation 'com.engagelab.plugin:vivo:5.3.0' // ここではバージョン5.3.0を例として使用しています。
// オプション:音声ブロードキャスト機能
implementation 'com.engagelab.plugin:oth_sound:5.3.0' // ここではバージョン5.3.0を例として使用しています。
}
このコードブロックはフローティングウィンドウ内に表示されます
Kotlin DSL (build.gradle.kts):
dependencies {
// 必須:メインパッケージ
implementation("com.engagelab:engagelab:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:Googleベンダー
implementation("com.engagelab.plugin:google:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:栄耀ベンダー
implementation("com.engagelab.plugin:honor:5.3.0") // ここではバージョン5.3.0を例として使用しています。
implementation("com.engagelab.plugin:honor_th_push:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:華為ベンダー
implementation("com.engagelab.plugin:huawei:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:小米ベンダー(中国版)
implementation("com.engagelab.plugin:mi:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:魅族ベンダー
implementation("com.engagelab.plugin:meizu:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// 魅族ベンダー:SDK 5.2.0以降、魅族を統合するには「com.engagelab.plugin:meizu_th_push」が必要です。5.2.0より前は不要です。
implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:OPPOベンダー
implementation("com.engagelab.plugin:oppo:5.3.0") // ここではバージョン5.3.0を例として使用しています。
implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:vivoベンダー
implementation("com.engagelab.plugin:vivo:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:音声ブロードキャスト機能
implementation("com.engagelab.plugin:oth_sound:5.3.0") // ここではバージョン5.3.0を例として使用しています。
}
dependencies {
// 必須:メインパッケージ
implementation("com.engagelab:engagelab:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:Googleベンダー
implementation("com.engagelab.plugin:google:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:栄耀ベンダー
implementation("com.engagelab.plugin:honor:5.3.0") // ここではバージョン5.3.0を例として使用しています。
implementation("com.engagelab.plugin:honor_th_push:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:華為ベンダー
implementation("com.engagelab.plugin:huawei:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:小米ベンダー(中国版)
implementation("com.engagelab.plugin:mi:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:魅族ベンダー
implementation("com.engagelab.plugin:meizu:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// 魅族ベンダー:SDK 5.2.0以降、魅族を統合するには「com.engagelab.plugin:meizu_th_push」が必要です。5.2.0より前は不要です。
implementation("com.engagelab.plugin:meizu_th_push:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:OPPOベンダー
implementation("com.engagelab.plugin:oppo:5.3.0") // ここではバージョン5.3.0を例として使用しています。
implementation("com.engagelab.plugin:oppo_th_push:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:vivoベンダー
implementation("com.engagelab.plugin:vivo:5.3.0") // ここではバージョン5.3.0を例として使用しています。
// オプション:音声ブロードキャスト機能
implementation("com.engagelab.plugin:oth_sound:5.3.0") // ここではバージョン5.3.0を例として使用しています。
}
このコードブロックはフローティングウィンドウ内に表示されます
2. build.gradleの設定
Groovy (build.gradle):
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// アプリパッケージ名(コンソールのものと一致する必要があります)
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// AppKey(コンソールのものと一致する必要があります。packageNameと一対一の関係)
ENGAGELAB_PRIVATES_APPKEY : "YourAppKey",
// Engagelabアプリチャネル(チャネル統計に使用)
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelabプロセス(Engagelab SDKが動作するプロセス。注:「:」で始まる必要があります)
ENGAGELAB_PRIVATES_PROCESS: ":remote",
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
// アプリパッケージ名(コンソールのものと一致する必要があります)
applicationId "com.engagelab.app"
...
manifestPlaceholders = [
// AppKey(コンソールのものと一致する必要があります。packageNameと一対一の関係)
ENGAGELAB_PRIVATES_APPKEY : "YourAppKey",
// Engagelabアプリチャネル(チャネル統計に使用)
ENGAGELAB_PRIVATES_CHANNEL: "developer",
// Engagelabプロセス(Engagelab SDKが動作するプロセス。注:「:」で始まる必要があります)
ENGAGELAB_PRIVATES_PROCESS: ":remote",
]
}
}
dependencies {
implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
}
このコードブロックはフローティングウィンドウ内に表示されます
Kotlin DSL (build.gradle.kts):
plugins {
alias(libs.plugins.android.application)
}
android {
// ...
defaultConfig {
// アプリパッケージ名(コンソールのものと一致する必要があります)
applicationId = "com.engagelab.app"
// ...
manifestPlaceholders.putAll(mapOf(
// AppKey(コンソールのものと一致する必要があります。packageNameと一対一の関係)
"ENGAGELAB_PRIVATES_APPKEY" to "YourAppKey",
// Engagelabアプリチャネル(チャネル統計に使用)
"ENGAGELAB_PRIVATES_CHANNEL" to "developer",
// Engagelabプロセス(Engagelab SDKが動作するプロセス。注:「:」で始まる必要があります)
"ENGAGELAB_PRIVATES_PROCESS" to ":remote"
))
}
}
dependencies {
implementation(fileTree(mapOf("include" to listOf("*.jar", "*.aar"), "dir" to "libs")))
}
plugins {
alias(libs.plugins.android.application)
}
android {
// ...
defaultConfig {
// アプリパッケージ名(コンソールのものと一致する必要があります)
applicationId = "com.engagelab.app"
// ...
manifestPlaceholders.putAll(mapOf(
// AppKey(コンソールのものと一致する必要があります。packageNameと一対一の関係)
"ENGAGELAB_PRIVATES_APPKEY" to "YourAppKey",
// Engagelabアプリチャネル(チャネル統計に使用)
"ENGAGELAB_PRIVATES_CHANNEL" to "developer",
// Engagelabプロセス(Engagelab SDKが動作するプロセス。注:「:」で始まる必要があります)
"ENGAGELAB_PRIVATES_PROCESS" to ":remote"
))
}
}
dependencies {
implementation(fileTree(mapOf("include" to listOf("*.jar", "*.aar"), "dir" to "libs")))
}
このコードブロックはフローティングウィンドウ内に表示されます
必要なコンポーネントの作成
Java:
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* 開発者はMTCommonServiceを拡張して、長い接続の存続期間を延ばすことができます。
*
* 空の実装で十分です。
*/
public class UserService extends MTCommonService {
}
package com.engagelab.app.component;
import com.engagelab.privates.common.component.MTCommonService;
/**
* 開発者はMTCommonServiceを拡張して、長い接続の存続期間を延ばすことができます。
*
* 空の実装で十分です。
*/
public class UserService extends MTCommonService {
}
このコードブロックはフローティングウィンドウ内に表示されます
Kotlin:
package com.engagelab.app.component
import com.engagelab.privates.common.component.MTCommonService
class UserService : MTCommonService() {}
package com.engagelab.app.component
import com.engagelab.privates.common.component.MTCommonService
class UserService : MTCommonService() {}
このコードブロックはフローティングウィンドウ内に表示されます
Java:
package com.engagelab.app.component;
import android.content.Context;
import android.widget.Toast;
import java.util.Arrays;
import com.engagelab.app.common.ExampleGlobal;
import com.engagelab.app.listener.StatusObserver;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.common.component.MTCommonReceiver;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.core.api.WakeMessage;
import com.engagelab.privates.push.api.CustomMessage;
import com.engagelab.privates.push.api.MobileNumberMessage;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.api.PlatformTokenMessage;
/**
* 開発者はMTCommonReceiverを拡張して、SDKからのメソッドコールバックを受信できます。
*
* すべてのコールバックはメインスレッドで実行されます。
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* アプリケーション通知スイッチ状態のコールバック。
*
* @param context 非null
* @param enable 通知スイッチ状態。trueはオン、falseはオフを示します。
*/
@Override
public void onNotificationStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onNotificationStatus:" + enable);
Toast.makeText(context.getApplicationContext(), "onNotificationStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isNotificationEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onNotificationStatus(enable);
}
}
/**
* 長い接続状態のコールバック。
*
* @param context 非null
* @param enable 接続が確立されているかどうか
*/
@Override
public void onConnectStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onConnectState:" + enable);
Toast.makeText(context.getApplicationContext(), "onConnectStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isConnectEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onConnectStatus(enable);
}
// 長い接続が確立されたときにregistrationIdを取得
if (enable) {
String registrationId = MTCorePrivatesApi.getRegistrationId(context);
ExampleLogger.i(TAG, "registrationId:" + registrationId);
}
}
/**
* 通知メッセージ到着のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
}
/**
* フォアグラウンドで表示されない通知メッセージのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString());
}
/**
* 通知メッセージクリックのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
}
/**
* 通知メッセージ削除のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
}
/**
* カスタムメッセージのコールバック。
*
* @param context 非null
* @param customMessage カスタムメッセージ
*/
@Override
public void onCustomMessage(Context context, CustomMessage customMessage) {
ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
}
/**
* ベンダートークンメッセージのコールバック。
*
* @param context 非null
* @param platformTokenMessage ベンダートークンメッセージ
*/
@Override
public void onPlatformToken(Context context, PlatformTokenMessage platformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:" + platformTokenMessage.toString());
}
}
package com.engagelab.app.component;
import android.content.Context;
import android.widget.Toast;
import java.util.Arrays;
import com.engagelab.app.common.ExampleGlobal;
import com.engagelab.app.listener.StatusObserver;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.common.component.MTCommonReceiver;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.core.api.WakeMessage;
import com.engagelab.privates.push.api.CustomMessage;
import com.engagelab.privates.push.api.MobileNumberMessage;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.api.PlatformTokenMessage;
/**
* 開発者はMTCommonReceiverを拡張して、SDKからのメソッドコールバックを受信できます。
*
* すべてのコールバックはメインスレッドで実行されます。
*/
public class UserReceiver extends MTCommonReceiver {
private static final String TAG = "UserReceiver";
/**
* アプリケーション通知スイッチ状態のコールバック。
*
* @param context 非null
* @param enable 通知スイッチ状態。trueはオン、falseはオフを示します。
*/
@Override
public void onNotificationStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onNotificationStatus:" + enable);
Toast.makeText(context.getApplicationContext(), "onNotificationStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isNotificationEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onNotificationStatus(enable);
}
}
/**
* 長い接続状態のコールバック。
*
* @param context 非null
* @param enable 接続が確立されているかどうか
*/
@Override
public void onConnectStatus(Context context, boolean enable) {
ExampleLogger.i(TAG, "onConnectState:" + enable);
Toast.makeText(context.getApplicationContext(), "onConnectStatus " + enable, Toast.LENGTH_SHORT).show();
ExampleGlobal.isConnectEnable = enable;
if (StatusObserver.getInstance().getListener() != null) {
StatusObserver.getInstance().getListener().onConnectStatus(enable);
}
// 長い接続が確立されたときにregistrationIdを取得
if (enable) {
String registrationId = MTCorePrivatesApi.getRegistrationId(context);
ExampleLogger.i(TAG, "registrationId:" + registrationId);
}
}
/**
* 通知メッセージ到着のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationArrived(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:" + notificationMessage.toString());
}
/**
* フォアグラウンドで表示されない通知メッセージのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationUnShow(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:" + notificationMessage.toString());
}
/**
* 通知メッセージクリックのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationClicked(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:" + notificationMessage.toString());
}
/**
* 通知メッセージ削除のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
@Override
public void onNotificationDeleted(Context context, NotificationMessage notificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:" + notificationMessage.toString());
}
/**
* カスタムメッセージのコールバック。
*
* @param context 非null
* @param customMessage カスタムメッセージ
*/
@Override
public void onCustomMessage(Context context, CustomMessage customMessage) {
ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
}
/**
* ベンダートークンメッセージのコールバック。
*
* @param context 非null
* @param platformTokenMessage ベンダートークンメッセージ
*/
@Override
public void onPlatformToken(Context context, PlatformTokenMessage platformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:" + platformTokenMessage.toString());
}
}
このコードブロックはフローティングウィンドウ内に表示されます
Kotlin:
package com.engagelab.app.component
import android.content.Context
import android.widget.Toast
import com.engagelab.app.common.ExampleGlobal
import com.engagelab.app.listener.StatusObserver
import com.engagelab.app.log.ExampleLogger
import com.engagelab.privates.common.component.MTCommonReceiver
import com.engagelab.privates.core.api.MTCorePrivatesApi
import com.engagelab.privates.push.api.CustomMessage
import com.engagelab.privates.push.api.NotificationMessage
import com.engagelab.privates.push.api.PlatformTokenMessage
/**
* 開発者はMTCommonReceiverを拡張して、SDKからのメソッドコールバックを受信できます。
* すべてのコールバックはメインスレッドで実行されます。
*/
class UserReceiver : MTCommonReceiver() {
companion object {
private const val TAG = "UserReceiver"
}
/**
* アプリケーション通知スイッチ状態のコールバック。
*
* @param context 非null
* @param enable 通知スイッチ状態。trueはオン、falseはオフを示します。
*/
override fun onNotificationStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onNotificationStatus:$enable")
Toast.makeText(context.applicationContext, "onNotificationStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isNotificationEnable = enable
StatusObserver.getInstance().listener?.onNotificationStatus(enable)
}
/**
* 長い接続状態のコールバック。
*
* @param context 非null
* @param enable 接続が確立されているかどうか
*/
override fun onConnectStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onConnectState:$enable")
Toast.makeText(context.applicationContext, "onConnectStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isConnectEnable = enable
StatusObserver.getInstance().listener?.onConnectStatus(enable)
// 長い接続が確立されたときにregistrationIdを取得
if (enable) {
val registrationId = MTCorePrivatesApi.getRegistrationId(context)
ExampleLogger.i(TAG, "registrationId:$registrationId")
}
}
/**
* 通知メッセージ到着のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}")
}
/**
* フォアグラウンドで表示されない通知メッセージのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}")
}
/**
* 通知メッセージクリックのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}")
}
/**
* 通知メッセージ削除のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}")
}
/**
* カスタムメッセージのコールバック。
*
* @param context 非null
* @param customMessage カスタムメッセージ
*/
override fun onCustomMessage(context: Context, customMessage: CustomMessage) {
ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}")
}
/**
* ベンダートークンメッセージのコールバック。
*
* @param context 非null
* @param platformTokenMessage ベンダートークンメッセージ
*/
override fun onPlatformToken(context: Context, platformTokenMessage: PlatformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:${platformTokenMessage.toString()}")
}
}
package com.engagelab.app.component
import android.content.Context
import android.widget.Toast
import com.engagelab.app.common.ExampleGlobal
import com.engagelab.app.listener.StatusObserver
import com.engagelab.app.log.ExampleLogger
import com.engagelab.privates.common.component.MTCommonReceiver
import com.engagelab.privates.core.api.MTCorePrivatesApi
import com.engagelab.privates.push.api.CustomMessage
import com.engagelab.privates.push.api.NotificationMessage
import com.engagelab.privates.push.api.PlatformTokenMessage
/**
* 開発者はMTCommonReceiverを拡張して、SDKからのメソッドコールバックを受信できます。
* すべてのコールバックはメインスレッドで実行されます。
*/
class UserReceiver : MTCommonReceiver() {
companion object {
private const val TAG = "UserReceiver"
}
/**
* アプリケーション通知スイッチ状態のコールバック。
*
* @param context 非null
* @param enable 通知スイッチ状態。trueはオン、falseはオフを示します。
*/
override fun onNotificationStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onNotificationStatus:$enable")
Toast.makeText(context.applicationContext, "onNotificationStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isNotificationEnable = enable
StatusObserver.getInstance().listener?.onNotificationStatus(enable)
}
/**
* 長い接続状態のコールバック。
*
* @param context 非null
* @param enable 接続が確立されているかどうか
*/
override fun onConnectStatus(context: Context, enable: Boolean) {
ExampleLogger.i(TAG, "onConnectState:$enable")
Toast.makeText(context.applicationContext, "onConnectStatus $enable", Toast.LENGTH_SHORT).show()
ExampleGlobal.isConnectEnable = enable
StatusObserver.getInstance().listener?.onConnectStatus(enable)
// 長い接続が確立されたときにregistrationIdを取得
if (enable) {
val registrationId = MTCorePrivatesApi.getRegistrationId(context)
ExampleLogger.i(TAG, "registrationId:$registrationId")
}
}
/**
* 通知メッセージ到着のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationArrived(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationArrived:${notificationMessage.toString()}")
}
/**
* フォアグラウンドで表示されない通知メッセージのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationUnShow(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationUnShow:${notificationMessage.toString()}")
}
/**
* 通知メッセージクリックのコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationClicked(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationClicked:${notificationMessage.toString()}")
}
/**
* 通知メッセージ削除のコールバック。
*
* @param context 非null
* @param notificationMessage 通知メッセージ
*/
override fun onNotificationDeleted(context: Context, notificationMessage: NotificationMessage) {
ExampleLogger.i(TAG, "onNotificationDeleted:${notificationMessage.toString()}")
}
/**
* カスタムメッセージのコールバック。
*
* @param context 非null
* @param customMessage カスタムメッセージ
*/
override fun onCustomMessage(context: Context, customMessage: CustomMessage) {
ExampleLogger.i(TAG, "onCustomMessage:${customMessage.toString()}")
}
/**
* ベンダートークンメッセージのコールバック。
*
* @param context 非null
* @param platformTokenMessage ベンダートークンメッセージ
*/
override fun onPlatformToken(context: Context, platformTokenMessage: PlatformTokenMessage) {
ExampleLogger.i(TAG, "onPlatformToken:${platformTokenMessage.toString()}")
}
}
このコードブロックはフローティングウィンドウ内に表示されます
4. AndroidManifest.xmlの設定
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.engagelab.app">
<!-- 必須:インターネット権限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- オプション:通知の振動 -->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.engagelab.app.MainApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MT"
android:usesCleartextTraffic="true"
tools:targetApi="m"> <!-- HTTPリクエストを使用する場合は、HTTPを許可します -->
.....................................................................................................
<!-- このクラスの長い接続機能により、メーカーの省電力最適化によって、名前に「Engagelab」を含むパッケージ名のサービスが直接終了される可能性があります。 -->
<!-- したがって、開発者はcom.engagelab.app.component.MTCommonServiceを拡張して、長い接続の生存率を向上させ、メッセージ到達率を高める必要があります。 -->
<service
android:name="com.engagelab.app.component.UserService"
android:exported="false"
android:process="${ENGAGELAB_PRIVATES_PROCESS}">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_SERVICE" />
</intent-filter>
</service>
<!-- Engagelabビジネスコールバックを受信するために使用されます。長い接続状態/通知スイッチ状態/通知メッセージ到着/通知メッセージクリック/通知メッセージ削除/カスタムメッセージ/ベンダートークンコールバックを含みます。 -->
<!-- サブプロセスを設定する必要はありません。このコールバックはメインプロセスで実行され、ビジネス操作を容易にします。 -->
<receiver
android:name="com.engagelab.app.component.UserReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_RECEIVER" />
</intent-filter>
</receiver>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.engagelab.app">
<!-- 必須:インターネット権限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- オプション:通知の振動 -->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.engagelab.app.MainApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MT"
android:usesCleartextTraffic="true"
tools:targetApi="m"> <!-- HTTPリクエストを使用する場合は、HTTPを許可します -->
.....................................................................................................
<!-- このクラスの長い接続機能により、メーカーの省電力最適化によって、名前に「Engagelab」を含むパッケージ名のサービスが直接終了される可能性があります。 -->
<!-- したがって、開発者はcom.engagelab.app.component.MTCommonServiceを拡張して、長い接続の生存率を向上させ、メッセージ到達率を高める必要があります。 -->
<service
android:name="com.engagelab.app.component.UserService"
android:exported="false"
android:process="${ENGAGELAB_PRIVATES_PROCESS}">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_SERVICE" />
</intent-filter>
</service>
<!-- Engagelabビジネスコールバックを受信するために使用されます。長い接続状態/通知スイッチ状態/通知メッセージ到着/通知メッセージクリック/通知メッセージ削除/カスタムメッセージ/ベンダートークンコールバックを含みます。 -->
<!-- サブプロセスを設定する必要はありません。このコールバックはメインプロセスで実行され、ビジネス操作を容易にします。 -->
<receiver
android:name="com.engagelab.app.component.UserReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.engagelab.privates.intent.USER_RECEIVER" />
</intent-filter>
</receiver>
</application>
</manifest>
このコードブロックはフローティングウィンドウ内に表示されます
5. 環境設定
Java:
package com.engagelab.app;
import android.app.Application;
import com.engagelab.privates.core.api.Address;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
/**
* ENGAGELAB-sdkの設定をデモンストレーションするために使用されます。
*/
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// 設定はapplication.onCreateで行う必要があります。プロセスを確認する必要はありません。SDKに内部確認があります。
MTCorePrivatesApi.configDebugMode(this, true);
// プッシュを初期化します。
// MTPushPrivatesApi.init(this);
}
}
package com.engagelab.app;
import android.app.Application;
import com.engagelab.privates.core.api.Address;
import com.engagelab.privates.core.api.MTCorePrivatesApi;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
/**
* ENGAGELAB-sdkの設定をデモンストレーションするために使用されます。
*/
public class MainApplication extends Application {
private static final String TAG = "MainApplication";
@Override
public void onCreate() {
super.onCreate();
// 設定はapplication.onCreateで行う必要があります。プロセスを確認する必要はありません。SDKに内部確認があります。
MTCorePrivatesApi.configDebugMode(this, true);
// プッシュを初期化します。
// MTPushPrivatesApi.init(this);
}
}
このコードブロックはフローティングウィンドウ内に表示されます
Kotlin:
package com.engagelab.app
import android.app.Application
import com.engagelab.privates.core.api.MTCorePrivatesApi
import com.engagelab.privates.push.api.MTPushPrivatesApi
/**
* ENGAGELAB-sdkの設定デモ用。
*/
class MainApplication : Application() {
companion object {
private const val TAG = "MainApplication"
}
override fun onCreate() {
super.onCreate()
// application.onCreateで設定必須。プロセスの判定は不要。SDKが内部で判定します
MTCorePrivatesApi.configDebugMode(this, true)
// プッシュを初期化
MTPushPrivatesApi.init(this)
}
}
package com.engagelab.app
import android.app.Application
import com.engagelab.privates.core.api.MTCorePrivatesApi
import com.engagelab.privates.push.api.MTPushPrivatesApi
/**
* ENGAGELAB-sdkの設定デモ用。
*/
class MainApplication : Application() {
companion object {
private const val TAG = "MainApplication"
}
override fun onCreate() {
super.onCreate()
// application.onCreateで設定必須。プロセスの判定は不要。SDKが内部で判定します
MTCorePrivatesApi.configDebugMode(this, true)
// プッシュを初期化
MTPushPrivatesApi.init(this)
}
}
このコードブロックはフローティングウィンドウ内に表示されます
6. 通知クリックジャンプコンポーネントの作成
Java:
package com.engagelab.app.component;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.engagelab.app.R;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.constants.MTPushConstants;
/**
* 通知をクリックしてアクティビティにジャンプする例を示すために使用されます。
*
* MTPushPrivatesApi.reportNotificationOpened(Context, String, byte, String)を呼び出す必要はありません。SDKが内部で処理します。
*/
public class UserActivity400 extends Activity {
private static final String TAG = "UserActivity400";
private TextView tvMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent);
tvMessage = findViewById(R.id.tv_message);
onIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
onIntent(intent);
}
private void onIntent(Intent intent) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show();
if (intent == null) {
return;
}
// バージョン3.4.0から、オブジェクトは使用されなくなり、JSONデータが使用されます。
String notificationMessage = intent.getStringExtra("message_json");
if (notificationMessage == null) {
return;
}
ExampleLogger.d(TAG, "notificationMessage:" + notificationMessage.toString());
tvMessage.setText(notificationMessage.toString());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
package com.engagelab.app.component;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import com.engagelab.app.R;
import com.engagelab.app.log.ExampleLogger;
import com.engagelab.privates.push.api.MTPushPrivatesApi;
import com.engagelab.privates.push.api.NotificationMessage;
import com.engagelab.privates.push.constants.MTPushConstants;
/**
* 通知をクリックしてアクティビティにジャンプする例を示すために使用されます。
*
* MTPushPrivatesApi.reportNotificationOpened(Context, String, byte, String)を呼び出す必要はありません。SDKが内部で処理します。
*/
public class UserActivity400 extends Activity {
private static final String TAG = "UserActivity400";
private TextView tvMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intent);
tvMessage = findViewById(R.id.tv_message);
onIntent(getIntent());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
onIntent(intent);
}
private void onIntent(Intent intent) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show();
if (intent == null) {
return;
}
// バージョン3.4.0から、オブジェクトは使用されなくなり、JSONデータが使用されます。
String notificationMessage = intent.getStringExtra("message_json");
if (notificationMessage == null) {
return;
}
ExampleLogger.d(TAG, "notificationMessage:" + notificationMessage.toString());
tvMessage.setText(notificationMessage.toString());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}
}
このコードブロックはフローティングウィンドウ内に表示されます
Kotlin:
package com.engagelab.app.component
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import com.engagelab.app.R
import com.engagelab.app.log.ExampleLogger
import com.engagelab.privates.push.api.MTPushPrivatesApi
/**
* 通知クリック後のアクティビティジャンプのデモ用。
*
* MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String)を呼ぶ必要はありません。SDKが内部で処理します。
*/
class UserActivity400 : Activity() {
companion object {
private const val TAG = "UserActivity400"
}
private lateinit var tvMessage: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_intent)
tvMessage = findViewById(R.id.tv_message)
onIntent(intent)
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
onIntent(intent)
}
private fun onIntent(intent: Intent?) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show()
if (intent == null) {
return
}
// 3.4.0以降はオブジェクトではなくJSONデータを使用
val notificationMessage = intent.getStringExtra("message_json")
if (notificationMessage == null) {
return
}
ExampleLogger.d(TAG, "notificationMessage:$notificationMessage")
tvMessage.text = notificationMessage
} catch (throwable: Throwable) {
throwable.printStackTrace()
}
}
}
package com.engagelab.app.component
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import com.engagelab.app.R
import com.engagelab.app.log.ExampleLogger
import com.engagelab.privates.push.api.MTPushPrivatesApi
/**
* 通知クリック後のアクティビティジャンプのデモ用。
*
* MTPushPrivatesApi.reportNotificationOpened(Context, String, Byte, String)を呼ぶ必要はありません。SDKが内部で処理します。
*/
class UserActivity400 : Activity() {
companion object {
private const val TAG = "UserActivity400"
}
private lateinit var tvMessage: TextView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_intent)
tvMessage = findViewById(R.id.tv_message)
onIntent(intent)
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
onIntent(intent)
}
private fun onIntent(intent: Intent?) {
try {
Toast.makeText(this, TAG, Toast.LENGTH_SHORT).show()
if (intent == null) {
return
}
// 3.4.0以降はオブジェクトではなくJSONデータを使用
val notificationMessage = intent.getStringExtra("message_json")
if (notificationMessage == null) {
return
}
ExampleLogger.d(TAG, "notificationMessage:$notificationMessage")
tvMessage.text = notificationMessage
} catch (throwable: Throwable) {
throwable.printStackTrace()
}
}
}
このコードブロックはフローティングウィンドウ内に表示されます
7. クリックジャンプのためのAndroidManifest.xmlの設定
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.engagelab.app">
<!-- 必須:インターネット権限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- オプション:通知の振動 -->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.engagelab.app.MainApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MT"
android:usesCleartextTraffic="true"
tools:targetApi="m"> <!-- HTTPリクエストを使用する場合は、HTTPを許可します -->
..............................................................
<!-- 通知クリックジャンプをデモンストレーションするために使用されます -->
<activity
android:name="com.engagelab.app.component.UserActivity400"
android:exported="false"
android:launchMode="singleTask" />
<!-- ディープリンクを使用した通知クリックジャンプをデモンストレーションするために使用されます -->
<!-- <activity-->
<!-- android:name="com.engagelab.app.component.UserActivity400"-->
<!-- android:exported="false" >-->
<!-- <intent-filter>-->
<!-- <data android:scheme="YourScheme"/>-->
<!-- <data android:host="YourHost"/>-->
<!-- <action android:name="android.intent.action.VIEW" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <category android:name="android.intent.category.BROWSABLE" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<!-- ローカル転送検証のホワイトリスト:MTPush 4.2.3から、ENGAGELAB_PRIVATES_TRANSFERを設定した後、SDKはローカル検証を実行します。ローカル検証が有効にされている場合は、ここにジャンプ先のターゲットActivityを設定してください。複数のターゲットActivityがある場合は、「/」で区切ってください。 -->
<meta-data
android:name="ENGAGELAB_PRIVATES_TRANSFER"
android:value="com.engagelab.app.component.UserActivity400" />
<!-- Googleプッシュに必要:Googleチャネルを使用しない場合は削除してください -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
<!-- 華為プッシュに必要:華為チャネルを使用しない場合は削除してください -->
<meta-data
android:name="com.huawei.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.engagelab.app">
<!-- 必須:インターネット権限 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- オプション:通知の振動 -->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name="com.engagelab.app.MainApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MT"
android:usesCleartextTraffic="true"
tools:targetApi="m"> <!-- HTTPリクエストを使用する場合は、HTTPを許可します -->
..............................................................
<!-- 通知クリックジャンプをデモンストレーションするために使用されます -->
<activity
android:name="com.engagelab.app.component.UserActivity400"
android:exported="false"
android:launchMode="singleTask" />
<!-- ディープリンクを使用した通知クリックジャンプをデモンストレーションするために使用されます -->
<!-- <activity-->
<!-- android:name="com.engagelab.app.component.UserActivity400"-->
<!-- android:exported="false" >-->
<!-- <intent-filter>-->
<!-- <data android:scheme="YourScheme"/>-->
<!-- <data android:host="YourHost"/>-->
<!-- <action android:name="android.intent.action.VIEW" />-->
<!-- <category android:name="android.intent.category.DEFAULT" />-->
<!-- <category android:name="android.intent.category.BROWSABLE" />-->
<!-- </intent-filter>-->
<!-- </activity>-->
<!-- ローカル転送検証のホワイトリスト:MTPush 4.2.3から、ENGAGELAB_PRIVATES_TRANSFERを設定した後、SDKはローカル検証を実行します。ローカル検証が有効にされている場合は、ここにジャンプ先のターゲットActivityを設定してください。複数のターゲットActivityがある場合は、「/」で区切ってください。 -->
<meta-data
android:name="ENGAGELAB_PRIVATES_TRANSFER"
android:value="com.engagelab.app.component.UserActivity400" />
<!-- Googleプッシュに必要:Googleチャネルを使用しない場合は削除してください -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
<!-- 華為プッシュに必要:華為チャネルを使用しない場合は削除してください -->
<meta-data
android:name="com.huawei.messaging.default_notification_icon"
android:resource="@drawable/mtpush_notification_icon" />
</application>
</manifest>
このコードブロックはフローティングウィンドウ内に表示されます
