0

近くのメッセージ API を使用して、eddystone ビーコンからメッセージを取得しようとしています。私は次のドキュメントに従いました:

[ https://developers.google.com/nearby/messages/overview?hl=en][1]

デフォルトのデバッグ キーストアの SHA1 を使用しています。しかし、次のエラーメッセージが表示され続けます

 Nearby.Messages is not enabled for this app: packageName

デバイス: Nexus 6 (Android バージョン 5.1.1)

プレイ サービスのバージョン: 8.1.15

4

2 に答える 2

3

このエラーが発生するのは、Nearby API を使用するために必要なアクセス許可をユーザーに明示的に要求していないためです。これを行う 1 つの方法を次に示します。

// GoogleApiClient connection callback. Initiate permission check here.
@Override
public void onConnected(Bundle connectionHint) {
    Nearby.Messages.getPermissionStatus(mGoogleApiClient).setResultCallback(
            new ErrorCheckingCallback("getPermissionStatus", new Runnable() {
                @Override
                public void run() {
                    publishAndSubscribe();
                }
            })
    );
}


// This is called in response to a button tap in the Nearby permission dialog.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_RESOLVE_ERROR) {
        mResolvingError = false;
        if (resultCode == RESULT_OK) {
            // Permission granted or error resolved successfully then we proceed
            // with publish or subscribe..
            publishAndSubscribe();
        } else {
            // This may mean that user had rejected to grant nearby permission.
            showToast("Failed to resolve error with code " + resultCode);
        }
    }
}


/**
* A simple ResultCallback that displays a toast when errors occur.
* It also displays the Nearby opt-in dialog when necessary.
*/
private class ErrorCheckingCallback implements ResultCallback<Status> {
   private final String method;
   private final Runnable runOnSuccess;

   private ErrorCheckingCallback(String method) {
       this(method, null);
   }

   private ErrorCheckingCallback(String method, @Nullable Runnable runOnSuccess) {
       this.method = method;
       this.runOnSuccess = runOnSuccess;
   }

   @Override
   public void onResult(@NonNull Status status) {
       if (status.isSuccess()) {
           Log.i(TAG, method + " succeeded.");
           if (runOnSuccess != null) {
               runOnSuccess.run();
           }
       } else {
           // Currently, the only resolvable error is that the device is not opted
           // in to Nearby. Starting the resolution displays an opt-in dialog.
           if (status.hasResolution()) {
               if (!mResolvingError) {
                   try {
                       status.startResolutionForResult(MainActivity.this,
                               REQUEST_RESOLVE_ERROR);
                       mResolvingError = true;
                   } catch (IntentSender.SendIntentException e) {
                       showToastAndLog(Log.ERROR, method + " failed with exception: " + e);
                   }
               } else {
                   // This will be encountered on initial startup because we do
                   // both publish and subscribe together.  So having a toast while
                   // resolving dialog is in progress is confusing, so just log it.
                   Log.i(TAG, method + " failed with status: " + status
                           + " while resolving error.");
               }
           } else {
               showToastAndLog(Log.ERROR, method + " failed with : " + status
                       + " resolving error: " + mResolvingError);
           }
       }
   }
}

ドキュメントで完全な例を見つけることができます。

また、ガイドラインについて覚えておいてください。

  • ユーザーを驚かせないでください。Nearby を有効にするには、明示的なアクション (ボタンのタップ、アプリ内のセクションへの移動、特別なスイッチなど) を実行することをユーザーに要求します。

  • iOS と Android の両方で、Nearby を初めて呼び出すと、許可ダイアログがトリガーされます。Nearby を呼び出す前に明示的なユーザー アクションを待つことで、ユーザーはダイアログを文脈化し、それをアプリの近接ベースの機能に関連付けることができます。

于 2015-10-08T23:04:09.093 に答える
0

Nearby を使用する許可を明示的にユーザーに求める必要があります。Nearby API は、 EyesClearによって提供されるコードのショートカットを提供するようになりました。API クライアント ビルダーでenableAutoManageメソッドを呼び出すだけです。

詳細については、 https ://developers.google.com/nearby/messages/android/user-consent をご覧ください。

残念ながら、これはフォアグラウンド サブスクリプションでのみ機能します。

于 2016-11-03T14:17:17.990 に答える