LoginSignup
3
3

More than 5 years have passed since last update.

[翻訳] Nearby Messages API for Android (Publish and Subscribe)

Last updated at Posted at 2016-02-19

Nearby Messages API for Androidの Publish and Subscribe を翻訳してみました。
お気づきの点があればコメント頂ければと思います。

以下、関連する投稿へのリンクです。
■ Google Play services Nearby 公式 翻訳
■ Nearby Messages API (Overview) 公式 翻訳
■ Nearby Messages API for Android (Get Started) 公式 翻訳
Nearby Messages API for Android (Publish and Subscribe) 公式 翻訳

※ 公式ドキュメントでリンクがいくつか切れていましたが、修正していません。 ( =①ω①= )

Publish and Subscribe

Nearby Messages is a publish-subscribe API which lets nearby devices exchange small payloads of data. Once a device publishes a message, nearby devices can receive the message. This guide walks you through all of the functionality your app must implement in order to publish messages, and subscribe to messages using the Nearby Messages API.

The set of nearby devices is determined by the exchange of small tokens over Bluetooth and ultrasonic (inaudible) audio. When a device detects a token from a nearby device, it sends the token to the Nearby Messages server to validate it and check if there are any messages to deliver for the application’s current set of subscriptions.

An application can control the set of mediums used for device discovery, and whether the mediums are used to broadcast tokens and/or scan for tokens. By default, broadcasting and scanning is done on all the mediums. To do discovery on a subset or mediums, and to control whether to broadcast or scan, you must pass additional parameters when you create publications and subscriptions.

When actively publishing and subscribing, a "Nearby is in use" notification is presented, informing users that Nearby is active. This notification is only displayed when one or more apps are actively using Nearby, giving users a chance to conserve battery life if Nearby is not needed. It provides users with the following options:

  • Navigate to an app to disable Nearby.
  • Force an app to stop using Nearby.
  • Navigate to the Nearby Settings screen.

You can use PublishCallback() and SubscribeCallback() to listen for cases when a user forces the app to stop using Nearby. When this happens, the onExpired() method is triggered.

Because the Nearby Messages APIs have the potential to impact battery life, they should only be used from a foreground activity (with the exception of BLE background subscribe). Your activity should publish() or subscribe() either in onStart() or in response to a user action in a visible activity. Your app should always symetrically unpublish() or unsubscribe() in onStop(). Once there are no active publishes or subscribes, your app should call GoogleApiClient.disconnect().

The code examples in this guide are based on the NearbyDevices example app.

Nearby Messagesは、近くのデバイス間で小さなデータペイロードを取り交わせるようにするパブリッシュ-サブスクライブ APIです。 デバイスがメッセージをパブリッシュすると、近くのデバイスは、メッセージを受け取ることができます。 このガイドでは、あなたのアプリがNearby Messages APIを使用してメッセージをパブリッシュし、そしてメッセージをサブスクライブするために実装する必要があるすべての機能を紹介します。

近くのデバイスのセットは、Bluetoothと超音波を使った小さなトークンの取り交わしによって決定されます。 デバイスが近くのデバイスからのトークンを検出すると、そのトークンを検証し、アプリの現在のサブスクリプションセットに配信する何らかのメッセージがあるかチェックするため、そのトークンをNearby Messagesサーバーに送信します。

アプリはデバイスの検出に使われる導体のセットと、導体がトークンのブロードキャストやトークンのスキャンに使われるかどうかを制御できます。 デフォルトでは、ブロードキャストとスキャンはすべての導体で行われます。 導体のすべてまたは一部で検出を行うため、またブロードキャストまたはスキャンするかどうかを制御するために、あなたがパブリケーションとサブスクリプションを作成するとき、追加パラメータを渡す必要があります。

パブリッシュやサブスクライブしているとき、Nearbyが稼働していることをユーザーに知らせるため"Nearby使用中"の通知が表示されます。 この通知は一つ以上のアプリがNearbyを使用しているときのみ表示されます。 そしてNearbyが不要な時にユーザーがバッテリを節約する機会を与えます。 それは、次のオプションをユーザーに提供します:

  • Nearbyを無効にするためアプリに移動する。
  • Nearbyの使用を停止するようアプリに強制する。
  • Nearby設定画面に移動する。

ユーザーがNearbyの使用を停止するようアプリに強制したケースを受け取るため、 PublishCallback()SubscribeCallback() が使えます。 これが発生した時はonExpired()メソッドが呼ばれます。

Nearby Messages APIはバッテリ寿命に影響を与える可能性があるので、(BLEのバックグラウンド サブスクライブを除き)フォアグラウンドのactivityからのみ使われるべきです。 あなたのactivityはpublish()subscribe()を、onStart()または前面に見えているactivityに対するユーザー操作への応答として行うべきです。 あなたのアプリはunpublish()unsubscribe()onStop()で行うべきです。 アクティブなパブリッシュやサブスクライブが無くなったら、あなたのアプリはGoogleApiClient.disconnect()を呼ぶ必要があります。

このガイドのコード例は、NearbyDevicesサンプルアプリに基づいています。

Anatomy of a request

When making a request to publish a message, or to subscribe to messages from nearby devices, your app should do the following:

  1. Ensure that the Google API Client is connected.
  2. Call the appropriate method (publish(), subscribe(), unpublish(), unsubscribe()), using a result callback to handle the result code. In the case of subscriptions, also use a MessageListener to handle any messages that are received when subscribing.
  3. Set a flag to track the method that has been called (publish(), subscribe(), unpublish(), unsubscribe()). If a request fails for any reason, it goes away and must be re-initiated by the app. Your app can use this flag to resume any outstanding requests in the event of an error.
  4. Handle errors in the result callback. For example, if an error with the status code APP_NOT_OPTED_IN is received, the error handler calls startResolutionForResult to prompt the user for their consent.
  5. After handling any error, use onActivityResult to re-initiate the original request. If consent was not granted at the time of the original publish or subscribe request, you must re-call publish and/or subscribe in onActivityResult after getting user consent. The original request does not go through after consent is granted.
  6. Upon ending the activity stop all publish and subscribe tasks in onStop().

メッセージのパブリッシュや近くのデバイスからのメッセージのサブスクライブを行うときは、次のことを行う必要があります:

  1. Google API Clientに接続していることを確認します。

  2. 応答コードを受け取るためコールバックを使用して、適切なメソッド(publish(), subscribe(), unpublish(), unsubscribe())を呼び出します。 またサブスクリプションではメッセージ受信を処理するためにMessageListenerも使用します。

  3. 呼び出されたメソッド(publish(), subscribe(), unpublish(), unsubscribe())を追跡するためにフラグを設定します。 何らかの理由でリクエストが失敗した場合、フラグは消え、アプリによって再開される必要があります。 エラーイベントが発生した際に、アプリは未処理のリクエストを再開するためこのフラグを使用することが出来ます。

  4. コールバックに含まれるエラーに対応します。 例えば、APP_NOT_OPTED_INというステータスコードを受信した場合、エラーハンドラはユーザーに承諾を促すstartResolutionForResultを呼び出します。

  5. すべてのエラーを処理した後、元々のリクエストを再開するためにonActivityResultを使用します。 元々のパブリッシュまたはサブスクライブ時に承諾されていなかった場合、ユーザーの承諾を得た後にonActivityResultでパブリッシュやサブスクライブを再呼出する必要があります。 承諾が得られた後でも、元々のリクエストは継続されません。

  6. activity終了時には、onStop()で全てのパブリッシュとサブスクライブを停止します。

Publish a message

To publish a message, call Nearby.Messages.publish() passing your message byte array. Message size should be kept to 3KB or less to maintain good performance. This service is not meant for exchanging larger objects such as photos and videos.

Your app's implementation for publishing should do the following:

  • Check for a connection to the Google API Client, and connect the app if it is not already connected.
  • Use PublishOptions.Builder() to set the PublishOptions, calling setCallback() to set a callback which is triggered when the publish task ends.
  • Optionally, call setStrategy() to set the strategy to use. If this is not explicitly set, default strategy values will be used.
  • Call publish(), setting a ResultCallback with an error handler. The primary job of this handler is to detect whether the user has provided consent to use Nearby, and call the appropriate method to display a consent prompt for the user. You can also use this handler to deal with other error conditions that may arise.

The following example demonstrates calling publish() to send a small text message:

private void publish() {
    Log.i(TAG, "Trying to publish.");
    // Set a simple message payload.
    String strMsg = "This is NearbyPubSub.";
    mDeviceInfoMessage = new Message(strMsg.getBytes());
    // Cannot proceed without a connected GoogleApiClient.
    // Reconnect and execute the pending task in onConnected().
    if (!mGoogleApiClient.isConnected()) {
        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    } else {
        PublishOptions options = new PublishOptions.Builder()
                .setCallback(new PublishCallback() {
                    @Override
                    public void onExpired() {
                        Log.i(TAG, "No longer publishing.");
                    }
                }).build();
        Nearby.Messages.publish(mGoogleApiClient, mDeviceInfoMessage, options)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "Published successfully.");
                        } else {
                            Log.i(TAG, "Could not publish.");
                            // Check whether consent was given;
                            // if not, prompt the user for consent.
                            handleUnsuccessfulNearbyResult(status);
                        }
                    }
                });
    }
}

メッセージをパブリッシュするには、メッセージをバイト配列にして渡してNearby.Messages.publish()を呼び出します。 良いパフォーマンスを維持するため、メッセージのサイズは3KB以下にするべきです。 このサービスは、写真や動画などの大きなオブジェクトを取り交わすためのものではありません。

パブリッシュを実装するアプリは次のことを行う必要があります:

  • Google API Clientへの接続を確認し、接続されていない場合は接続します。
  • PublishOptionsを設定するためPublishOptions.Builder()を使用します。そしてパブリッシュが終わった時に発生するコールバックを設定するためsetCallback()を呼びます。

  • オプションでstrategyを設定するためsetStrategy()を呼びます。 明示的に設定されない場合、デフォルトのstrategyが使用されます。

  • publish()を呼び出し、エラーハンドラとResultCallbackを設定します。 このハンドラの主な仕事はNearbyの使用を承諾しているかどうかを検出し、ユーザーに承諾を促す表示を行うため適切なメソッドを呼び出すことです。 また、発生しうる他のエラーに対処するためにも、このハンドラを使用することができます。

次の例は、小さなテキストメッセージを送信するためのpublish()の呼出を示します。

private void publish() {
    Log.i(TAG, "Trying to publish.");
    // Set a simple message payload.
    String strMsg = "This is NearbyPubSub.";
    mDeviceInfoMessage = new Message(strMsg.getBytes());
    // Cannot proceed without a connected GoogleApiClient.
    // Reconnect and execute the pending task in onConnected().
    if (!mGoogleApiClient.isConnected()) {
        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    } else {
        PublishOptions options = new PublishOptions.Builder()
                .setCallback(new PublishCallback() {
                    @Override
                    public void onExpired() {
                        Log.i(TAG, "No longer publishing.");
                    }
                }).build();
        Nearby.Messages.publish(mGoogleApiClient, mDeviceInfoMessage, options)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "Published successfully.");
                        } else {
                            Log.i(TAG, "Could not publish.");
                            // Check whether consent was given;
                            // if not, prompt the user for consent.
                            handleUnsuccessfulNearbyResult(status);
                        }
                    }
                });
    }
}

Unpublish a message

To unpublish a message, call unpublish(). At minimum your app should call unpublish in its onStop() method.

Your app's implementation for unpublishing should do the following:

  • Call unpublish() with the same Message object that was used to publish (mDeviceInfoMessage in this example).

The following code example shows calling unpublish():

private void unpublish() {
    Log.i(TAG, "Trying to unpublish.");
    Nearby.Messages.unpublish(mGoogleApiClient, mDeviceInfoMessage);
}

メッセージのパブリッシュを止めるため、unpublish()を呼び出します。 最低でもあなたのアプリは、onStop()でunpublishを呼び出すべきです。

パブリッシュを止める実装は、次のことを行う必要があります。

  • publishで使用したのと同じMessageオブジェクトでunpublish()を呼び出します。(この例ではmDeviceInfoMessage

次のコードの例は、unpublish()の呼出を示します。

private void unpublish() {
    Log.i(TAG, "Trying to unpublish.");
    Nearby.Messages.unpublish(mGoogleApiClient, mDeviceInfoMessage);
}

Subscribe to messages

To subscribe to messages from other devices, call Nearby.Messages.subscribe().

Your app's implementation for subscribing should do the following:

  • Check for a connection to the Google API Client, and connect the app if it is not already connected.
  • Use SubscribeOptions.Builder() to set the SubscribeOptions, calling setStrategy() to set the subscribe strategy, and setCallback() to set a callback which is triggered when the subscribe task ends.
  • Call subscribe(), setting a ResultCallback with an error handler. The primary job of this handler is to detect whether the user has provided consent to use Nearby, and call the appropriate method to display a consent prompt for the user. You can also use this handler to deal with other error conditions that may arise.
  • Create a MessageListener instance to handle receiving subscribed messages. In this example, the MessageListener instance is defined in the onCreateView() method for the Fragment.

The following example demonstrates subscribing to messages:

// Subscribe to receive messages.
private void subscribe() {
    Log.i(TAG, "Trying to subscribe.");
    // Cannot proceed without a connected GoogleApiClient.
    // Reconnect and execute the pending task in onConnected().
    if (!mGoogleApiClient.isConnected()) {
        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    } else {
        SubscribeOptions options = new SubscribeOptions.Builder()
                .setCallback(new SubscribeCallback() {
                    @Override
                    public void onExpired() {
                        Log.i(TAG, "No longer subscribing.");
                    }
                }).build();
        Nearby.Messages.subscribe(mGoogleApiClient, mMessageListener, options)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "Subscribed successfully.");
                        } else {
                            Log.i(TAG, "Could not subscribe.");
                            // Check whether consent was given;
                            // if not, prompt the user for consent.
                            handleUnsuccessfulNearbyResult(status);
                        }
                    }
                });
    }
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view =  inflater.inflate(R.layout.fragment_main, container, false);
    // Create a new message listener.
    mMessageListener = new MessageListener() {
        @Override
        public void onFound(final Message message) {
            final String nearbyMessageString = new String(message.getContent());
            // Do something with the message string.
            Log.i(TAG, nearbyMessageString);
        }
        // Called when a message is no longer detectable nearby.
        public void onLost(final Message message) {
            final String nearbyMessageString = new String(message.getContent());
            // Take appropriate action here (update UI, etc.)
        }
    }
    return view;
}

他のデバイスからのメッセージをサブスクライブするには、Nearby.Messages.subscribe()を呼び出します。

サブスクライブの実装では、次のことを行う必要があります。

  • Google API Clientへの接続を確認し、接続されていない場合は接続します。

  • SubscribeOptionsを設定するためSubscribeOptions.Builder()を使用し、サブスクライブのstrategyを設定するためsetStrategy()を呼び出し、サブスクライブが終わったときに発生するコールバックを設定するため、setCallback()を呼び出します。

  • subscribe() を呼び出し、エラーハンドラとResultCallbackを設定します。 このハンドラの主な仕事はNearbyの使用を承諾しているかどうかを検出し、ユーザーに承諾を促す表示を行うため適切なメソッドを呼び出すことです。 また発生しうる他のエラーに対処するためにも、このハンドラを使用することができます。

  • サブスクライブされたメッセージの受信を処理するため、MessageListenerのインスタンスを作成します。 この例では、MessageListenerのインスタンスはFragmentのonCreateView()メソッドで定義されています。

次の例は、メッセージのサブスクライブを示します:

// Subscribe to receive messages.
private void subscribe() {
    Log.i(TAG, "Trying to subscribe.");
    // Cannot proceed without a connected GoogleApiClient.
    // Reconnect and execute the pending task in onConnected().
    if (!mGoogleApiClient.isConnected()) {
        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    } else {
        SubscribeOptions options = new SubscribeOptions.Builder()
                .setCallback(new SubscribeCallback() {
                    @Override
                    public void onExpired() {
                        Log.i(TAG, "No longer subscribing.");
                    }
                }).build();
        Nearby.Messages.subscribe(mGoogleApiClient, mMessageListener, options)
                .setResultCallback(new ResultCallback<Status>() {
                    @Override
                    public void onResult(Status status) {
                        if (status.isSuccess()) {
                            Log.i(TAG, "Subscribed successfully.");
                        } else {
                            Log.i(TAG, "Could not subscribe.");
                            // Check whether consent was given;
                            // if not, prompt the user for consent.
                            handleUnsuccessfulNearbyResult(status);
                        }
                    }
                });
    }
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view =  inflater.inflate(R.layout.fragment_main, container, false);
    // Create a new message listener.
    mMessageListener = new MessageListener() {
        @Override
        public void onFound(final Message message) {
            final String nearbyMessageString = new String(message.getContent());
            // Do something with the message string.
            Log.i(TAG, nearbyMessageString);
        }
        // Called when a message is no longer detectable nearby.
        public void onLost(final Message message) {
            final String nearbyMessageString = new String(message.getContent());
            // Take appropriate action here (update UI, etc.)
        }
    }
    return view;
}

Unsubscribe

To unsubscribe and stop receiving device messages, call Nearby.Messages.unsubscribe().

Your app's implementation for unsubscribing should do the following:

The following code example demonstrates unsubscribing:

private void unsubscribe() {
    Log.i(TAG, "Trying to unsubscribe.");
    Nearby.Messages.unsubscribe(mGoogleApiClient, mMessageListener);
}

サブスクライブを止めて、デバイスのメッセージ受信を止めるためには、Nearby.Messages.unsubscribe()を呼び出します。

サブスクライブを止める実装では、次のことを行う必要があります:

  • サブスクライブに使用したのと同じMessageListenerオブジェクトでunsubscribe()を呼び出します。 (この例ではmMessageListener

次のコードの例は、サブスクライブの停止を示します:

private void unsubscribe() {
    Log.i(TAG, "Trying to unsubscribe.");
    Nearby.Messages.unsubscribe(mGoogleApiClient, mMessageListener);
}

Implement the runtime consent flow

The Nearby Messages API requires user consent. Prior to making any requests, your app must check to see whether the user has consented, and present them with a consent dialog if they have not. To implement the runtime consent flow in your app, you can either:

Implement a result callback

In the result callback, call status.getStatusCode() to check the error status code. If the status code APP_NOT_OPTED_IN is received, display the consent dialog by calling status.startResolutionForResult(), and use onActivityResult() to re-initiate any outstanding subscription or publication requests.

The following example shows a simple result callback that checks to see whether the user has provided consent; if the user has not consented, status.startResolutionForResult() is called to prompt the user to opt-in to Nearby Messages. In this example, the boolean mResolvingError is used to avoid triggering multiple consent prompts.

private void handleUnsuccessfulNearbyResult(Status status) {
    Log.i(TAG, "Processing error, status = " + status);
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (status.hasResolution()) {
        try {
            mResolvingError = true;
            status.startResolutionForResult(getActivity(),
                    Constants.REQUEST_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            mResolvingError = false;
            Log.i(TAG, "Failed to resolve error status.", e);
        }
    } else {
        if (status.getStatusCode() == CommonStatusCodes.NETWORK_ERROR) {
            Toast.makeText(getActivity().getApplicationContext(),
                    "No connectivity, cannot proceed. Fix in 'Settings' and try again.",
                    Toast.LENGTH_LONG).show();
        } else {
            // To keep things simple, pop a toast for all other error messages.
            Toast.makeText(getActivity().getApplicationContext(), "Unsuccessful: " +
                    status.getStatusMessage(), Toast.LENGTH_LONG).show();
        }
    }
}

You can also use this handler to handle any other NearbyMessageStatusCodes resulting from the operation, or other status codes such as CommonStatusCodes.NETWORK_ERROR.

Re-initiate outstanding requests

The following example shows an onActivityResult(), which is called after the user has responded to the opt-in dialog. If the user consents, any pending subscription or publication tasks are executed (in this case, a method called executePendingTasks() is called).

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Constants.REQUEST_RESOLVE_ERROR) {
        // User was presented with the Nearby opt-in dialog and pressed "Allow".
        mResolvingError = false;
        if (resultCode == Activity.RESULT_OK) {
            // Execute the pending subscription and publication tasks here.
            mMainFragment.executePendingTasks();
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // User declined to opt-in. Reset application state here.
        } else {
            Toast.makeText(this, "Failed to resolve error with code " + resultCode,
                    Toast.LENGTH_LONG).show();
        }
    }

Nearby Messages APIはユーザーの承諾を必要とします。 何らかのリクエストを行う前に、あなたのアプリはユーザーが承諾済みかどうかチェックし、未承諾なら承諾を促すダイアログを表示する必要があります。 あなたのアプリが実行時に承諾を得るフローは次のいずれかです:

  • publish()subscribe()の呼出にコールバックを加える。
  • publish()subscribe()の呼出の前に承諾の有無をチェックするためNearby.Messages.getPermissionStatus()を呼び出す。

コールバックの実装

コールバックを受け取ったら、エラーステータスコードをチェックするためstatus.getStatusCode()を呼び出します。 もしステータスコードAPP_NOT_OPTED_INを受け取った場合、status.startResolutionForResult()を呼び出し、承諾を促すダイアログを表示します。 そして未処理のサブスクリプションまたはパブリケーションを再開するためonActivityResult()を使用します。

次の例はユーザーが承諾を出したかどうかチェックするためのシンプルなコールバックを示します。 ユーザーが承諾を行っていない場合、ユーザーにNearby Messagesへの同意を促すためstatus.startResolutionForResult()を呼び出しています。 この例では、ブール値mResolvingErrorは承諾画面が複数出ることを避けるために使用されています。

private void handleUnsuccessfulNearbyResult(Status status) {
    Log.i(TAG, "Processing error, status = " + status);
    if (mResolvingError) {
        // Already attempting to resolve an error.
        return;
    } else if (status.hasResolution()) {
        try {
            mResolvingError = true;
            status.startResolutionForResult(getActivity(),
                    Constants.REQUEST_RESOLVE_ERROR);
        } catch (IntentSender.SendIntentException e) {
            mResolvingError = false;
            Log.i(TAG, "Failed to resolve error status.", e);
        }
    } else {
        if (status.getStatusCode() == CommonStatusCodes.NETWORK_ERROR) {
            Toast.makeText(getActivity().getApplicationContext(),
                    "No connectivity, cannot proceed. Fix in 'Settings' and try again.",
                    Toast.LENGTH_LONG).show();
        } else {
            // To keep things simple, pop a toast for all other error messages.
            Toast.makeText(getActivity().getApplicationContext(), "Unsuccessful: " +
                    status.getStatusMessage(), Toast.LENGTH_LONG).show();
        }
    }
}

あなたはまた、他のNearbyMessageStatusCodesCommonStatusCodes.NETWORK_ERRORのようなステータスを処理するためにも、このハンドラを使用できます。

未処理のリクエストを再開する

次のサンプルはユーザーが同意ダイアログに応じた後に呼ばれるonActivityResult()を示します。 ユーザーが承諾した場合、保留中のサブスクリプションやパブリケーションは実行されます。
(この例ではexecutePendingTasks()という名前のメソッドが呼ばれます)

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == Constants.REQUEST_RESOLVE_ERROR) {
        // User was presented with the Nearby opt-in dialog and pressed "Allow".
        mResolvingError = false;
        if (resultCode == Activity.RESULT_OK) {
            // Execute the pending subscription and publication tasks here.
            mMainFragment.executePendingTasks();
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // User declined to opt-in. Reset application state here.
        } else {
            Toast.makeText(this, "Failed to resolve error with code " + resultCode,
                    Toast.LENGTH_LONG).show();
        }
    }
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3