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 サブスクライブ・サーブレットの使用

登録済みデバイスに通知を送信するときは 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 February 28, 2020