(Unity AWS SDK)未能获得Google云消息注册ID

时间:2016-08-21 21:54:16

标签: android unity3d google-cloud-messaging amazon-sns

我正在使用amazon aws sdk进行统一并试图让推送通知正常工作,所以在google开发人员控制台设置项目并启用后 GCM当我尝试运行应用程序时说它未能获得GCM注册ID,在查看其他类似问题后,我确保我的清单设置正确。

这是清单文件:

    <?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazonaws.unity"
  android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">

  <supports-screens
  android:smallScreens="true"
  android:normalScreens="true"
  android:largeScreens="true"
  android:xlargeScreens="true"
  android:anyDensity="true"/>

  <uses-sdk android:minSdkVersion="9" />


  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"      />

  <permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE"
  android:protectionLevel="signature" />
  <uses-permission android:name="com.amazonaws.unity.permission.C2D_MESSAGE" />


  <application
  android:theme="@android:style/Theme.NoTitleBar"
  android:icon="@drawable/app_icon"
  android:label="@string/app_name"
  android:debuggable="true">

  <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
          android:label="@string/app_name">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
  </intent-filter>
  <meta-data android:name="unityplayer.UnityActivity" android:value="true"  />
  <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik"  android:value="false" />
  </activity>

    <receiver
     android:name="com.google.android.gcm.GCMBroadcastReceiver"
     android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
     <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
    <category android:name="com.amazonaws.unity" />
    </intent-filter>
    </receiver>

  <service android:name="com.amazonaws.unity.GCMIntentService" />
  </application>
  </manifest>

检索注册ID的代码部分:

        if(string.IsNullOrEmpty(GoogleConsoleProjectId))
        {
            Debug.Log("sender id is null");
            debug.text = "sender id is null";
            return;
        }
        GCM.Register((regId) =>
        {

            if(string.IsNullOrEmpty(regId))
            {
                ResultText.text = string.Format("Failed to get the registration id");
                    debug.text = "Failed to get the registration id";

                return;
            }

            ResultText.text = string.Format(@"Your registration Id is = {0}", regId);

            SnsClient.CreatePlatformEndpointAsync(
                new CreatePlatformEndpointRequest
                {
                    Token = regId,
                    PlatformApplicationArn = AndroidPlatformApplicationArn
                },
                (resultObject) =>
                {
                    if(resultObject.Exception==null)
                    {
                        CreatePlatformEndpointResponse response = resultObject.Response;
                        _endpointArn = response.EndpointArn;
                        ResultText.text += string.Format(@"Platform endpoint arn is = {0}", response.EndpointArn);
                    }
                }
            );
        }, GoogleConsoleProjectId);

1 个答案:

答案 0 :(得分:1)

在实施Configuring the Unity Sample App for Android中给出的步骤之前,请确保您拥有Amazon Simple Notification Service中提供的以下 Android先决条件

  • 安装Android SDK
  • 安装JDK
  • 机器人支撑-v4.jar
  • google-play-services.jar

请注意Unity Sample (Android)

中给出的概念
  

该应用会显示两个标记为注册通知取消注册的按钮。点击注册通知按钮后,将调用RegisterDevice()方法。 RegisterDevice()调用GCM.Register,向GCM注册应用。它进行异步调用以向GCM注册应用程序。

除了给定的AWS文档,您还可以查看此AWS论坛有关Unity SNS example的信息。