Windows Azure通知中心,我的应用程序不会收到通知

时间:2014-10-29 19:10:37

标签: java android broadcastreceiver azure-mobile-services azure-notificationhub

我的应用程序似乎没有收到我发送给它的通知,使用azure站点内的调试模式,发送测试通知,我也尝试通过一些无效的.net代码发送通知,似乎就像我的通知中心正在接收这些通知但我的手机上的应用程序没有,互联网正在运行,usb-debugging已启用,并且我没有收到“收到herpderp通知”的日志。

我已在通知中心成功注册了我的应用程序,正在等待使用以下代码进行回复:

  gcm = GoogleCloudMessaging.getInstance(this);
    String connectionString = "***THIS IS where my connection string is, and it doesn't contain errors";
    hub = new NotificationHub("denlillemandhub", connectionString, this);
    NotificationsManager.handleNotifications(this, SENDER_ID, MyHandler.class);
    registerWithGcm();

registerWithGcm()方法:

 private void registerWithGcm() {
    new AsyncTask() {
        @Override
        protected Object doInBackground(Object... params) {
            try {
                registrationId = gcm.register(SENDER_ID);
                Log.i(TAG, "Registered with id: " + registrationId);

            } catch (Exception e) {
                return e;
            }
            return null;
        }
        protected void onPostExecute(Object result) {
            Log.d("Done", "attempt to register was done loading");
            /**lblRegistration.setText(mRegistrationId);
            lblStatus.setText(getResources().getString(R.string.status_registered)); */
        };
    }.execute(null, null, null);
}

MyHandler类(我将notificationHandler作为参数):

 import com.microsoft.windowsazure.notifications.NotificationsHandler;
  public class MyHandler extends NotificationsHandler
  {
  public static final int NOTIFICATION_ID = 1;
  private NotificationManager mNotificationManager;
  NotificationCompat.Builder builder;
  Context ctx;

   @Override
  public void onReceive(Context context, Bundle bundle) {
    ctx = context;
    String nhMessage = bundle.getString("msg");
    Log.d("line 27", "onReceive");
    sendNotification(nhMessage);
}

private void sendNotification(String msg) {
    Log.d("line 32", "sendNotification");
    mNotificationManager = (NotificationManager)
            ctx.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
            new Intent(ctx, ToDoActivity.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(ctx)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("Notification Hub Demo")
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(msg))
                    .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

}

和last(我的androidManifest只是show权限):

    <uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="com.example.denlillemand.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.example.denlillemand.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />


<receiver android:name="com.microsoft.windowsazure.notifications.NotificationsBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />

        <category android:name="com.example.denlillemand" />
    </intent-filter>
</receiver>

我的兴奋是假设我在服务器端的脚本是正确的,那就是 我的GCM / Azure API密钥/设置都是正确的。显然我的通知中心收到了它的假设,但似乎GCM要么没有提供给已注册的设备,要么设备确实收到通知,但是没有正确处理它。

我要感谢任何想要阅读所有这些内容的人,以便给予一个有价值的猜测,我非常感谢你们,我非常感激不尽。

感谢。

1 个答案:

答案 0 :(得分:0)

在行

之后的 registerWithGcm()方法中
registrationId = gcm.register(SENDER_ID);
Log.i(TAG, "Registered with id: " + registrationId);

添加:

hub.register(registrationId);