Android のエンドツーエンドのデモンストレーション

improve this page | report issue

概説

このデモンストレーションの目的は、エンドツーエンドのフローを体験することです。

  1. MobileFirst クライアント SDK と事前にバンドルされているサンプル・アプリケーションは登録済みで、MobileFirst Operations Console からダウンロードされています。
  2. 新規または提供済みのアダプターは MobileFirst Operations Console にデプロイされています。
  3. アプリケーション・ロジックは、リソース要求を行うために変更されています。

終了結果:

  • MobileFirst Server を正常に ping している。
  • アダプターを使用してデータを正常に取得している。

前提条件:

1. MobileFirst Server の開始

Mobile Foundation インスタンスが作成済みであることを確認してください。作成済みでない場合は、
MobileFirst Developer Kitを使用しているときは、サーバーのフォルダーにナビゲートして、Mac および Linux では ./run.sh、Windows では run.cmd のコマンドを実行してください。

2. アプリケーションの作成

ブラウザー・ウィンドウで、URL http://your-server-host:server-port/mfpconsole をロードして MobileFirst Operations Console を開きます。 ローカルで実行している場合は、http://localhost:9080/mfpconsole を使用します。 ユーザー名/パスワードは admin/admin です。

  1. アプリケーションの隣の「新規」ボタンをクリックします。
    • Android プラットフォームを選択します。
    • com.ibm.mfpstarterandroidアプリケーション ID として入力します。
    • 1.0version の値として入力します。
    • 「アプリケーションの登録」をクリックします。

    アプリケーションの登録

  2. 「スターター・コードの取得」タイルをクリックして、Android サンプル・アプリケーションをダウンロードすることを選択します。

    サンプル・アプリケーションのダウンロード

3. アプリケーション・ロジックの編集

  1. Android Studio プロジェクトを開いて、プロジェクトをインポートします。

  2. 「プロジェクト (Project)」サイドバー・メニューから、「app」→「Java」→「com.ibm.mfpstarterandroid」→「ServerConnectActivity.java」ファイルを選択します。

  • 以下のインポートを追加します。

    import java.net.URI;
    import java.net.URISyntaxException;
    import android.util.Log;
    
  • 以下のコード・スニペットを貼り付けて、WLAuthorizationManager.getInstance().obtainAccessToken への呼び出しを置換します。

    WLAuthorizationManager.getInstance().obtainAccessToken("", new WLAccessTokenListener() {
                  @Override
                  public void onSuccess(AccessToken token) {
                      System.out.println("Received the following access token value: " + token);
                      runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                              titleLabel.setText("Yay!");
                              connectionStatusLabel.setText("Connected to MobileFirst Server");
                          }
                      });
    
                      URI adapterPath = null;
                      try {
                          adapterPath = new URI("/adapters/javaAdapter/resource/greet");
                      } catch (URISyntaxException e) {
                          e.printStackTrace();
                      }
    
                      WLResourceRequest request = new WLResourceRequest(adapterPath, WLResourceRequest.GET);
    
                      request.setQueryParameter("name","world");
                      request.send(new WLResponseListener() {
                          @Override
                          public void onSuccess(WLResponse wlResponse) {
                              // Will print "Hello world" in LogCat.
                              Log.i("MobileFirst Quick Start", "Success: " + wlResponse.getResponseText());
                          }
    
                          @Override
                  public void onFailure(WLFailResponse wlFailResponse) {
                              Log.i("MobileFirst Quick Start", "Failure: " + wlFailResponse.getErrorMsg());
                          }
                      });
                  }
    
                  @Override
                  public void onFailure(WLFailResponse wlFailResponse) {
                      System.out.println("Did not receive an access token from server: " + wlFailResponse.getErrorMsg());
                      runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                              titleLabel.setText("Bummer...");
                              connectionStatusLabel.setText("Failed to connect to MobileFirst Server");
                          }
                      });
                  }
              });
    

4. アダプターのデプロイ

この作成済みの .adapter 成果物をダウンロードし、MobileFirst Operations Console から「アクション」→「アダプターのデプロイ」アクションを使用して、この成果物をデプロイします。

あるいは、「アダプター」の隣の「新規」ボタンをクリックします。

  1. 「アクション」→「サンプルのダウンロード」オプションを選択します。 「Hello World」Java アダプターのサンプルをダウンロードします。

    Maven および MobileFirst CLI がインストールされていない場合は、スクリーン内の「開発環境をセットアップします」の説明に従います。

  2. コマンド・ライン・ウィンドウからアダプターの Maven プロジェクト・ルート・フォルダーにナビゲートし、以下のコマンドを実行します。

    mfpdev adapter build
    
  3. ビルドが終了したら、「アクション」→「アダプターのデプロイ」アクションを使用して MobileFirst Operations Console からアダプターをデプロイします。 アダプターは、[adapter]/target フォルダー内にあります。

    アダプターのデプロイ

サンプル・アプリケーション

5. アプリケーションのテスト

  1. Android Studio で、「プロジェクト (Project)」サイドバー・メニューで、「app」→「src」→「main」→「assets」→「mfpclient.properties」ファイルを選択し、ご使用の MobileFirst Server の正しい値で protocolhost、および port の各プロパティーを編集します。
    • ローカル MobileFirst Server を使用している場合、通常、値は httplocalhost、および 9080 です。
    • リモート MobileFirst Server (IBM Cloud 上) を使用している場合、通常、値は httpsyour-server-address、および 443 です。
    • IBM Cloud Private 上で Kubernetes クラスターを使用していて、デプロイメントのタイプが NodePort の場合、通常、ポートの値は、Kubernetes クラスターのサービスによって公開される NodePort です。

    あるいは、MobileFirst CLI がインストール済みの場合は、プロジェクト・ルート・フォルダーにナビゲートし、コマンド mfpdev app register を実行します。 リモート MobileFirst Server が使用されている場合は、コマンド mfpdev server add を実行してサーバーを追加し、続いて、例えば、mfpdev app register myIBMCloudServer を実行します。

  2. 「アプリケーションの実行 (Run App)」ボタンをクリックします。


結果

  • 「MobileFirst Server への ping (Ping MobileFirst Server)」ボタンをクリックすると、「MobileFirst Server に接続されています (Connected to MobileFirst Server)」が表示されます。
  • アプリケーションが MobileFirst Server に接続できた場合は、デプロイした Java アダプターを使用してリソース要求呼び出しが行われます。

その場合、アダプター応答が Android Studio の LogCat ビューに出力されます。

 MobileFirst Server からリソースを正常に呼び出したアプリケーションのイメージ

次の手順

アプリケーションでのアダプターの使用、プッシュ通知などの追加のサービスを統合する方法、MobileFirst セキュリティー・フレームワークの使用などについて学習します。

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