在 Android 中处理 SMS 通知

improve this page | report issue


概述

SMS 通知是推送通知的一个子集,因此请务必先阅读在 Android 中查看推送通知教程。

先决条件:

跳转至:

通知 API

在 SMS 通知中,当注册设备时,将传递电话号码值。

验证问题处理程序

如果 push.mobileclient 作用域映射到安全性检查,那么需要确保在使用任何推送 API 之前,存在已注册的匹配验证问题处理程序

初始化

在客户机应用程序使用适当的应用程序上下文连接到 MFPPush 服务时为必需项。

  • 应先调用此 API 方法,然后再使用任何其他 MFPPush API。
  • 注册回调函数以处理已收到的推送通知。
MFPPush.getInstance().initialize(this);

注册设备

向推送通知服务注册设备。

MFPPush.getInstance().registerDevice(new MFPPushResponseListener<String>() {
    @Override
    public void onSuccess(String s) {
        // Successfully registered
    }

    @Override
    public void onFailure(MFPPushException e) {
        // Registration failed with error
    }
}, optionObject);
  • optionObject:一个 JSONObject,其包含注册设备所用的电话号码。 例如:
JSONObject optionObject = new JSONObject();
try {
    // Obtain the inputted phone number.
    optionObject.put("phoneNumber", editPhoneText.getText().toString());
}
catch(Exception ex) {
    ex.printStackTrace();
}

也可以使用推送设备注册 (POST) REST API 来注册设备

注销设备

从推送通知服务实例注销设备。

MFPPush.getInstance().unregisterDevice(new MFPPushResponseListener<String>() {
    @Override
    public void onSuccess(String s) {
        disableButtons();
        // Unregistered successfully
    }

    @Override
    public void onFailure(MFPPushException e) {
        // Failed to unregister
    }
});

使用 SMS 预订 servlet

可使用 REST API 将通知发送到已注册的设备。 可以发送所有形式的通知:标记通知、广播通知和已认证的通知

要发送通知,可使用 POST 向 REST 端点发出请求:imfpush/v1/apps/<application-identifier>/messages
示例 URL:

https://myserver.com:443/imfpush/v1/apps/com.sample.sms/messages

要查看所有推送通知 REST API,请参阅用户文档中的 REST API 运行时服务主题。

要发送通知,请参阅发送通知教程。

样本应用程序图像

样本应用程序

单击以下载 Android 项目。

注:要运行此样本,需要在任何 Android 设备上安装最新版本的 Google Play Services。

用法样例

请查看样本的 README.md 文件以获取指示信息。

Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on June 01, 2020