跳转到内容

移动 SDK 参考

将新设备注册到您的 FlareLane 项目。当 requestPermissionOnLaunch 设为 true 时,应用启动后会立即请求通知权限。

/*
Params
- Context context
- String projectId
- boolean requestPermissionOnLaunch
*/
FlareLane.initWithContext(this, "INPUT_YOUR_PROJECT_ID", true)

设置 SDK 的日志级别。

/*
Params
- int logLevel
- Log.VERBOSE
- Log.ERROR
*/
FlareLane.setLogLevel(Log.VERBOSE)

检查该设备是否已订阅通知。如果尚未授予权限,则返回 false

/*
Android SDK >= 1.4.0
Params
- Context context
Return
- boolean isSubscribed
*/
FlareLane.isSubscribed(this)

将该设备订阅到通知。如果尚未授予权限,会先显示权限弹窗,或将用户引导至系统设置。

/*
Android SDK >= 1.4.0
Params
- Context context
- boolean fallbackToSettings - directs the user to the notification settings when the permission prompt cannot be shown
- @Nullable IsSubscribedHandler
*/
FlareLane.subscribe(this, true, FlareLane.IsSubscribedHandler {
// Do Something...
})

取消该设备的通知订阅。

/*
Android SDK >= 1.4.0
Params
- Context context
- @Nullable IsSubscribedHandler
*/
FlareLane.unsubscribe(this, FlareLane.IsSubscribedHandler {
// Do Something...
})

通常,您会在用户成功注册或登录时设置 User ID,以区分已注册用户和访客。

/*
Params
- Context context
- @Nullable String userId
*/
// SET
FlareLane.setUserId(this, "USER_ID")
// REMOVE
FlareLane.setUserId(this, null)

触发一个事件。如果设备已设置 User ID,事件会归属到该用户;否则归属到该单个设备。

/*
Params
- Context context
- String type
- @Nullable JSONObject data
*/
FlareLane.trackEvent(this, "test_event", null)
// OR
var tags = JSONObject()
tags.put("key", "value")
FlareLane.trackEvent(this, "test_event", tags)

设置标签。如果设备已设置 User ID,标签会归属到该用户;否则归属到该单个设备。

/*
Params
- Context context
- JSONObject tags
*/
var tags = JSONObject()
tags.put("gender", "men")
tags.put("age", 24)
tags.put("removeTag", JSONObject.NULL) // remove
FlareLane.setTags(this, tags)
/*
Params
- Context context
*/
FlareLane.getDeviceId(this);

注册一个回调处理器,当用户点击通知并打开应用时执行。

/*
Params
- public interface setNotificationClickedHandler
- onClicked(Notification notification)
- Notification
- @NonNull String id
- @Nullable String title
- @NonNull String body
- @Nullable String url
- @Nullable String imageUrl
*/
FlareLane.setNotificationClickedHandler(NotificationClickedHandler { notification ->
// Do Something...
})

注册一个回调处理器,当应用处于前台时收到通知会执行。您还可以控制是否显示该通知。

/*
SDK Version >= 1.5.0
Params
- public interface NotificationForegroundReceivedHandler
- onWillDisplay(NotificationReceivedEvent event);
- NotificationReceivedEvent
- Notification getNotification()
- void display()
*/
FlareLane.setNotificationForegroundReceivedHandler { event ->
Log.d("FlareLane", event.notification.toString())
// Call the function below to display the notification.
event.display()
}

在指定分组中,显示当前设备符合展示条件且优先级最高的应用内消息。

/*
SDK Version >= 1.7.0
Params
- String group
*/
FlareLane.displayInApp("home")

定义一个自定义处理器,用于处理由应用内消息触发的自定义操作。

/*
SDK Version >= 1.7.0
Params
- public interface InAppMessageActionHandler
- onExecute(InAppMessage iam, String actionId)
*/
FlareLane.setInAppMessageActionHandler(object : InAppMessageActionHandler {
override fun onExecute(iam: InAppMessage, actionId: String) {
// Do Something...
}
})