SNS移动推送 [英] SNS Mobile Push

查看:219
本文介绍了SNS移动推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Xamarin开发一个Android应用程序。我正在使用AWS SNS Push和Google Cloud Messenger(GCM)。



我一直非常关注此演练:
http://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/ getting-started-sns-android.html



我一直在使用的代码与其中的代码非常相似。但是,我有一个注册意向服务,它的工作原理如下:

pre $ [code> [Service(Exported = false)]
public class RegistrationIntentService:IntentService
{
private static object locker = new object();

RegistrationIntentService():base(RegistrationIntentService){}

保护覆盖无效OnHandleIntent(意图意图)
{
尝试
{
Logging.LogMessage(Application,RegistrationIntentService,Calling InstanceID.GetToken,LogType.Debug);
lock(locker)
{
var instanceID = InstanceID.GetInstance(Application.Context);
Constants.token = instanceID.GetToken(
Constants.senderId,GoogleCloudMessaging.InstanceIdScope,null);

Logging.LogMessage(应用程序,RegistrationIntentService,GCM注​​册令牌:+ Constants.token,LogType.Debug);
/*SendRegistrationToAppServer(token).GetAwaiter()。GetResult();

Log.Info(RegistrationIntentService,Registered); * /

SendRegistrationToAppServer(Constants.token).GetAwaiter()。GetResult();

Logging.LogMessage(Application,RegistrationIntentService,Registered,LogType.Debug);

订阅(Constants.token);
} //释放锁

}
catch(异常e)
{
Logging.LogMessage(Application,RegistrationIntentService,Failed to get例外:\ n+ e.ToString(),LogType.Error);



私有异步System.Threading.Tasks.Task SendRegistrationToAppServer(字符串标记)
{
var config = new AmazonSimpleNotificationServiceConfig()
{
RegionEndpoint = RegionEndpoint.USEast1
};

var credentials = new BasicAWSCredentials(Constants.accessKeyId,Constants.secretAccessKey);

Constants.client = new AmazonSimpleNotificationServiceClient(credentials,config);

Logging.LogMessage(这是RegistrationIntentService.SendRegistrationToAppServer,创建客户端,LogType.Debug);

if(Constants.createdEndpoint == null)
{
var endpoint = new CreatePlatformEndpointRequest()
{
PlatformApplicationArn = Constants.endPoint,
令牌=令牌
};

var endpointResponse =等待Constants.client.CreatePlatformEndpointAsync(endpoint);
Logging.LogMessage(this,RegistrationIntentService.SendRegistrationToAppServer,Got endpoint。ARN:+ endpointResponse.EndpointArn,LogType.Debug);
Constants.createdEndpoint = endpointResponse.EndpointArn;
}

//确保我们还没有订阅
if(Constants.createdEndpoint!= null&&& Constants.subscriptionArn == null)
{
var subscription = await Constants.client.SubscribeAsync(Constants.topicARNBeginning + Constants.devicePhoneNumber,Application,Constants.createdEndpoint);
Logging.LogMessage(这是RegistrationIntentService.SendRegistrationToAppServer,AWS Subscribed,LogType.Debug);


$ b $ private bool订阅(字符串标记)
{
var pubSub = GcmPubSub.GetInstance(Application.Context);
const string topic =/ topics / global;

尝试
{
pubSub.Subscribe(token,topic,null);
Logging.LogMessage(这是RegistrationIntentService.Subscribe,GCM订阅,LogType.Debug);
返回true;

catch(Java.IO.IOException)
{
try
{
pubSub.Unsubscribe(token,topic);

pubSub.Subscribe(token,topic,null);

返回true;

catch(Java.IO.IOException)
{
Logging.LogMessage(Application,Subscribe,Failed to register,LogType.Error);
返回false;
}
}
}
}

I通过MainActivity OnCreate事件处理程序中的StartService()调用显式启动注册意图服务。我确信我在文档中设置了所有需要的权限:
$ b $ pre $ [assembly:UsesPermission(Android.Manifest.Permission .ReceiveBootCompleted)]
[assembly:UsesPermission(Android.Manifest.Permission.Internet)]
[assembly:UsesPermission(Android.Manifest.Permission.WakeLock)]
[assembly:UsesPermission(Android .Manifest.Permission.Vibrate)]
[assembly:UsesPermission(com.google.android.c2dm.permission.RECEIVE)]
[assembly:Permission(Name =@ PACKAGE_NAME @ .permission。 C2D_MESSAGE,ProtectionLevel = Protection.Signature)]
[assembly:UsesPermission(@ PACKAGE_NAME @ .permission.C2D_MESSAGE)]
[assembly:UsesPermission(com.google.android.c2dm.permission。 SEND)]

我通过AssemblyInfo.cs和适当的C#属性创建了大部分Android Manifest例如[Service]属性)。我唯一明确声明的XML(除了应用程序)如下所示:

 < receiver android:name = com.google.android.gms.gcm.GcmReceiverandroid:exported =trueandroid:permission =com.google.android.c2dm.permission.SEND> 
< intent-filter>
< category android:name =com.gcmmessaging/>
< / intent-filter>
< / receiver>

以下是最终清单:

 <?xml version =1.0encoding =UTF-8?> 
< manifest android:installLocation =autoandroid:versionName =1.0android:versionCode =1package =com.gcmmessagingxmlns:android =http://schemas.android.com/ APK / RES /机器人>
< uses-sdk android:minSdkVersion =16/>
< uses-permission android:name =android.permission.INTERNET/>
<使用权限android:name =android.permission.READ_EXTERNAL_STORAGE/>
< permission android:name =com.gcmmessaging.permission.C2D_MESSAGEandroid:protectionLevel =signature/>
< uses-permission android:name =android.permission.WRITE_EXTERNAL_STORAGE/>
< uses-permission android:name =android.permission.RECEIVE_BOOT_COMPLETED/>
<使用权限android:name =android.permission.READ_PHONE_STATE/>
< uses-permission android:name =com.google.android.c2dm.permission.RECEIVE/>
<使用权限android:name =android.permission.WAKE_LOCK/>
< uses-permission android:name =android.permission.VIBRATE/>
<使用权限android:name =com.gcmmessaging.permission.C2D_MESSAGE/>
<使用权限android:name =com.google.android.c2dm.permission.SEND/>
< uses-permission android:name =android.permission.ACCESS_NETWORK_STATE/>
<使用权限android:name =android.permission.ACCESS_WIFI_STATE/>
< application android:name =mono.android.app.Application
android:allowBackup =true
android:debuggable =true
android:icon = @ drawable / sns_icon_48
android:label =ProductName>
< receiver android:name =com.google.android.gms.gcm.GcmReceiver
android:permission =com.google.android.c2dm.permission.SEND
android :导出= 真 >
< intent-filter>
< category android:name =com.gcmmessaging/>
< / intent-filter>
< / receiver>
< meta-data android:name =com.google.android.gms.version
android:value =@ integer / google_play_services_version/>
< activity android:name =[ConfigurationName]
android:label =Configuration/>
< receiver android:name =md503b8085957a5cb3d4167d0e7cbb2a6b0.GCMBootReceiver>
< intent-filter>
< / intent-filter>
< / receiver>
< service android:name =md503b8085957a5cb3d4167d0e7cbb2a6b0.GCMIntentServiceandroid:exported =false/>
< receiver android:name =md503b8085957a5cb3d4167d0e7cbb2a6b0.GCMBroadcastReceiverandroid:permission =com.google.android.c2dm.permission.SEND>
<! - 我确实想过要把所有这些都放在一个单一的 - >
< intent-filter>
< category android:name =com.gcmmessaging/>
< / intent-filter>
< intent-filter>
< category android:name =com.gcmmessaging/>
< / intent-filter>
< intent-filter>
< category android:name =com.gcmmessaging/>
< / intent-filter>
< / receiver>
< activity android:name =[Activityname]android:label =History/>
< service android:name =md503b8085957a5cb3d4167d0e7cbb2a6b0.MyInstanceIdListenerServiceandroid:exported =false>
< intent-filter>
< / intent-filter>
< / service>
< activity android:name =[ActivityName]android:icon =@ drawable / sns_icon_32android:label =ProductName>
< intent-filter>
< category android:name =android.intent.category.LAUNCHER/>
< / intent-filter>
< / activity>
< service android:name =md503b8085957a5cb3d4167d0e7cbb2a6b0.RegistrationIntentServiceandroid:exported =false/>
< receiver android:name =md5343e36a1bb0d551a047a1a24886e23d0.NetworkReachability_NetworkStatusChangeBroadcastReceiver/>
< provider android:name =com.google.android.gms.measurement.AppMeasurementContentProviderandroid:exported =falseandroid:authorities =com.gcmmessaging.google_measurement_service/>
< service android:name =com.google.android.gms.measurement.AppMeasurementServiceandroid:exported =falseandroid:enabled =true/>
< receiver android:name =com.google.android.gms.measurement.AppMeasurementReceiverandroid:enabled =true>
< intent-filter>
< / intent-filter>
< / receiver>
< provider android:name =mono.MonoRuntimeProviderandroid:exported =falseandroid:authorities =com.gcmmessaging.mono.MonoRuntimeProvider .__ mono_init__android:initOrder =2147483647/>
<! - suppress ExportedReceiver - >
< receiver android:name =mono.android.Seppuku>
< intent-filter>
< action android:name =mono.android.intent.action.SEPPUKU/>
< category android:name =mono.android.intent.category.SEPPUKU.com.gcmmessaging/>
< / intent-filter>
< / receiver>
< / application>
< / manifest>

这是我的广播接收器:

  [BroadcastReceiver(Permission =com.google.android.c2dm.permission.SEND)] 
[IntentFilter(new string [] {
com.google。 android.c2dm.intent.RECEIVE},Categories = new string [] {
@ PACKAGE_NAME @})]
[IntentFilter(new string [] {
com.google。 android.c2dm.intent.REGISTRATION},Categories = new string [] {
@ PACKAGE_NAME @})]
[IntentFilter(new string [] {
com.google。 android.gcm.intent.RETRY},Categories = new string [] {
@ PACKAGE_NAME @})]
public class GCMBroadcastReceiver:WakefulBroadcastReceiver
{
// // private const string TAG =PushHandlerBroadcastReceiver;

public override void OnReceive(Context context,Intent intent)
{
Logging.LogMessage(context,GCMBroadcastReceiver.OnReceive,Received message,LogType.Debug);

GCMIntentService.RunIntentInService(context,intent);
SetResult(Result.Ok,null,null);

Logging.LogMessage(context,GCMBroadcastReceiver.OnReceive,Ran intent service,LogType.Debug);
}
}

我目前收到一个GCM令牌并订阅GCM, SNS正确。我仔细检查了那里的返回代码,我肯定会得到一个有效的GCM令牌,我的订阅显示在SNS中。我的电话订阅GCM成功,没有抛出任何例外。但是,我实际上没有收到任何推动。我知道事实上,AWS实际上是发布数据(如果我创建电子邮件订阅,我会收到我发送的所有内容)。我也知道这些问题不是由我的公司防火墙引起的 - 如果我尝试通过4G实现它,它也会失败。



我确实遇到以下两个错误我的日志:
03-11 16:33:08.914 E / GcmReceiver(7749):无法解析目标意图服务,跳过类名执行
03-11 16:33:08.914 E / GcmReceiver(7749) :传递消息时出错:未找到ServiceIntent。



我不确定这些是否是原因。我还没有找到一个好的决议,这些在线尚未。



任何人有什么建议尝试(或如何去调试这个)?

解决方案

您正在混合使用API​​,对于使用新InstanceId的一方API来获取令牌,而在其他情况下,您可以使用旧的方式通过wakefulbroadcastreceiver接收数据,用GcmListenerService的派生类型替换接收器,如下所示:

  [Service(Exported = false),IntentFilter(new [] {com.google.android.c2dm.intent.RECEIVE})] 
public class SignalGCMReceiver:GcmListenerService
{

public override void OnMessageReceived(string from,Bundle data)
{
Console.WriteLine(data.ToString());


$ b $ / code $ / pre

最后在接收器上添加清单(接收器由服务内部实现):

 < receiver android:name =com.google.android。 gms.gcm.GcmReceiverandroid:exported =trueandroid:permission =com.google.android.c2dm.permission.SEND> 
< intent-filter>
< category android:name =@ PACKAGE_NAME @/>
< / intent-filter>
< / receiver>


I am currently developing an Android app in Xamarin. I am using AWS SNS Push and Google Cloud Messenger (GCM).

I've been following this walkthrough pretty closely: http://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/getting-started-sns-android.html

The code I've been working with is extremely similar to what's there. However, I have a Registration Intent Service that works as follows:

  [Service(Exported = false)]
  public class RegistrationIntentService : IntentService
  {
    private static object locker = new object();

    public RegistrationIntentService() : base("RegistrationIntentService") { }

    protected override void OnHandleIntent(Intent intent)
    {
        try
        {
            Logging.LogMessage(Application, "RegistrationIntentService", "Calling InstanceID.GetToken", LogType.Debug);
            lock (locker)
            {
                var instanceID = InstanceID.GetInstance(Application.Context);
                Constants.token = instanceID.GetToken(
                    Constants.senderId, GoogleCloudMessaging.InstanceIdScope, null);

                Logging.LogMessage(Application, "RegistrationIntentService", "GCM Registration Token: " + Constants.token, LogType.Debug);
                /*SendRegistrationToAppServer(token).GetAwaiter().GetResult();

                Log.Info("RegistrationIntentService", "Registered");*/

                SendRegistrationToAppServer(Constants.token).GetAwaiter().GetResult();

                Logging.LogMessage(Application, "RegistrationIntentService", "Registered", LogType.Debug);

                Subscribe(Constants.token);
            } // Release lock

        }
        catch (Exception e)
        {
            Logging.LogMessage(Application, "RegistrationIntentService", "Failed to get a registration token. Exception:\n" + e.ToString(), LogType.Error);
        }
    }

    private async System.Threading.Tasks.Task SendRegistrationToAppServer(string token)
    {
        var config = new AmazonSimpleNotificationServiceConfig()
        {
            RegionEndpoint = RegionEndpoint.USEast1
        };

        var credentials = new BasicAWSCredentials(Constants.accessKeyId, Constants.secretAccessKey);

        Constants.client = new AmazonSimpleNotificationServiceClient(credentials, config);

        Logging.LogMessage(this, "RegistrationIntentService.SendRegistrationToAppServer", "Created client", LogType.Debug);

        if (Constants.createdEndpoint == null)
        {
            var endpoint = new CreatePlatformEndpointRequest()
            {
                PlatformApplicationArn = Constants.endPoint,
                Token = token
            };

            var endpointResponse = await Constants.client.CreatePlatformEndpointAsync(endpoint);
            Logging.LogMessage(this, "RegistrationIntentService.SendRegistrationToAppServer", "Got endpoint. ARN: " + endpointResponse.EndpointArn, LogType.Debug);
            Constants.createdEndpoint = endpointResponse.EndpointArn;
        }

        // Make sure we haven't subscribed yet
        if (Constants.createdEndpoint != null && Constants.subscriptionArn == null)
        {
            var subscription = await Constants.client.SubscribeAsync(Constants.topicARNBeginning + Constants.devicePhoneNumber, "Application", Constants.createdEndpoint);
            Logging.LogMessage(this, "RegistrationIntentService.SendRegistrationToAppServer", "AWS Subscribed", LogType.Debug);
        }
    }

    private bool Subscribe(string token)
    {
        var pubSub = GcmPubSub.GetInstance(Application.Context);
        const string topic = "/topics/global";

        try
        {
            pubSub.Subscribe(token, topic, null);
            Logging.LogMessage(this, "RegistrationIntentService.Subscribe", "GCM Subscribed", LogType.Debug);
            return true;
        }
        catch (Java.IO.IOException)
        {
            try
            {
                pubSub.Unsubscribe(token, topic);

                pubSub.Subscribe(token, topic, null);

                return true;
            }
            catch (Java.IO.IOException)
            {
                Logging.LogMessage(Application, "Subscribe", "Failed to register", LogType.Error);
                return false;
            }
        }
    }
}

I start the Registration Intent Service explicitly with a StartService() call in the MainActivity OnCreate event handler. I made sure I set up all of the permissions called for in the documentation:

[assembly: UsesPermission(Android.Manifest.Permission.ReceiveBootCompleted)]
[assembly: UsesPermission (Android.Manifest.Permission.Internet)]
[assembly: UsesPermission (Android.Manifest.Permission.WakeLock)]
[assembly: UsesPermission(Android.Manifest.Permission.Vibrate)]
[assembly: UsesPermission("com.google.android.c2dm.permission.RECEIVE")]
[assembly: Permission(Name = "@PACKAGE_NAME@.permission.C2D_MESSAGE", ProtectionLevel = Protection.Signature)]
[assembly: UsesPermission("@PACKAGE_NAME@.permission.C2D_MESSAGE")]
[assembly: UsesPermission("com.google.android.c2dm.permission.SEND")]

I create most of my Android Manifest through the AssemblyInfo.cs and appropriate C# Attributes (e.g. the [Service] attribute). The only thing I explicitly declare in XML (other than the application) is as follows:

<receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" 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.gcmmessaging" />
        </intent-filter>
    </receiver>

Here's the final manifest:

<?xml version="1.0" encoding="UTF-8"?>
<manifest android:installLocation="auto" android:versionName="1.0" android:versionCode="1" package="com.gcmmessaging" xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-sdk android:minSdkVersion="16"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<permission android:name="com.gcmmessaging.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="com.gcmmessaging.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.SEND"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application android:name="mono.android.app.Application"
             android:allowBackup="true"
             android:debuggable="true"
             android:icon="@drawable/sns_icon_48"
             android:label="ProductName">
             <receiver android:name="com.google.android.gms.gcm.GcmReceiver"
                    android:permission="com.google.android.c2dm.permission.SEND"
                    android:exported="true">
                    <intent-filter>
                        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                        <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
                        <category android:name="com.gcmmessaging"/>
                    </intent-filter>
            </receiver>
            <meta-data android:name="com.google.android.gms.version"
                        android:value="@integer/google_play_services_version"/>
            <activity android:name="[ConfigurationName]"
                        android:label="Configuration"/>
            <receiver android:name="md503b8085957a5cb3d4167d0e7cbb2a6b0.GCMBootReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>
                </intent-filter>
            </receiver>
            <service android:name="md503b8085957a5cb3d4167d0e7cbb2a6b0.GCMIntentService" android:exported="false"/>
            <receiver android:name="md503b8085957a5cb3d4167d0e7cbb2a6b0.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
                <!-- It did occur to me to try to put all of these in a single  -->
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
                    <category android:name="com.gcmmessaging"/>
                    </intent-filter>
                <intent-filter>
                    <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
                    <category android:name="com.gcmmessaging"/>
                </intent-filter>
                <intent-filter>
                    <action android:name="com.google.android.gcm.intent.RETRY"/>
                    <category android:name="com.gcmmessaging"/>
                </intent-filter>
            </receiver>
            <activity android:name="[Activityname]" android:label="History"/>
            <service android:name="md503b8085957a5cb3d4167d0e7cbb2a6b0.MyInstanceIdListenerService" android:exported="false">
                <intent-filter>
                    <action android:name="com.google.android.gms.iid.InstanceID"/>
                </intent-filter>
            </service>
            <activity android:name="[ActivityName]" android:icon="@drawable/sns_icon_32" android:label="ProductName">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
            <service android:name="md503b8085957a5cb3d4167d0e7cbb2a6b0.RegistrationIntentService" android:exported="false"/>
            <receiver android:name="md5343e36a1bb0d551a047a1a24886e23d0.NetworkReachability_NetworkStatusChangeBroadcastReceiver"/>
            <provider android:name="com.google.android.gms.measurement.AppMeasurementContentProvider" android:exported="false" android:authorities="com.gcmmessaging.google_measurement_service"/>
            <service android:name="com.google.android.gms.measurement.AppMeasurementService" android:exported="false" android:enabled="true"/>
            <receiver android:name="com.google.android.gms.measurement.AppMeasurementReceiver" android:enabled="true">
                <intent-filter>
                    <action android:name="com.google.android.gms.measurement.UPLOAD"/>
                </intent-filter>
            </receiver>
            <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:authorities="com.gcmmessaging.mono.MonoRuntimeProvider.__mono_init__" android:initOrder="2147483647"/>
    <!--suppress ExportedReceiver-->
    <receiver android:name="mono.android.Seppuku">
        <intent-filter>
            <action android:name="mono.android.intent.action.SEPPUKU"/>
            <category android:name="mono.android.intent.category.SEPPUKU.com.gcmmessaging"/>
        </intent-filter>
    </receiver>
</application>
</manifest>

Here is my broadcast receiver:

[BroadcastReceiver(Permission = "com.google.android.c2dm.permission.SEND")]
[IntentFilter(new string[] {
  "com.google.android.c2dm.intent.RECEIVE"}, Categories = new string[] {
  "@PACKAGE_NAME@" })]
[IntentFilter(new string[] {
  "com.google.android.c2dm.intent.REGISTRATION"}, Categories = new string[] {
  "@PACKAGE_NAME@" })]
[IntentFilter(new string[] {
  "com.google.android.gcm.intent.RETRY"}, Categories = new string[] {
  "@PACKAGE_NAME@" })]
public class GCMBroadcastReceiver : WakefulBroadcastReceiver
{
    //private const string TAG = "PushHandlerBroadcastReceiver";

    public override void OnReceive(Context context, Intent intent)
    {
        Logging.LogMessage(context, "GCMBroadcastReceiver.OnReceive", "Received message", LogType.Debug);

        GCMIntentService.RunIntentInService(context, intent);
        SetResult(Result.Ok, null, null);

        Logging.LogMessage(context, "GCMBroadcastReceiver.OnReceive", "Ran intent service", LogType.Debug);
    }
}

I currently receive a GCM token and subscribe to GCM and SNS correctly. I checked the return codes there carefully and I'm definitely getting a valid-looking GCM token and my subscription shows up in SNS. My call to subscribe to GCM succeeds without throwing any exceptions. However, I don't actually receive any pushes. I know for a fact that AWS is, in fact, publishing the data (if I create an email subscription I receive everything I'm sending out). I also know that the issues aren't caused by my corporate firewall - if I try to do it over 4G it fails too.

I do get the two following errors in my logs: 03-11 16:33:08.914 E/GcmReceiver( 7749): Failed to resolve target intent service, skipping classname enforcement 03-11 16:33:08.914 E/GcmReceiver( 7749): Error while delivering the message: ServiceIntent not found.

I'm not sure if these are the cause or not. I haven't been able to find a good resolution to these online yet.

Anyone have any suggestions on what to try (or how to go about debugging this)? I'm truthfully at a bit of a loss here.

解决方案

You are mixing API's, for one side you use the new InstanceId API to get the token and in other you use the old way of receiving data with a wakefulbroadcastreceiver, replace your receiver with a derived type from GcmListenerService, something like this:

[Service (Exported = false), IntentFilter (new [] { "com.google.android.c2dm.intent.RECEIVE" })]
public class SignalGCMReceiver : GcmListenerService
{

    public override void OnMessageReceived (string from, Bundle data)
    {
        Console.WriteLine(data.ToString());

    }
}

And finally add the receiver on the manifest (the receiver is implemented internally by the service):

    <receiver android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" 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="@PACKAGE_NAME@" />
        </intent-filter>
    </receiver>

这篇关于SNS移动推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆