简体   繁体   English

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

[英]Windows Azure notification hub, my app doesn't receive notifications

My application doesn't seem to receive the notifications i send to it, using the debug mode inside the azure site, sending test notifications, i allso tried sending the notifications through some .net code which didn't work either, seems like my notification hub is receiveing these notifications but my application on the phone is not, internet is running, usb-debugging is on, and im not getting the logs that says "herpderp notification received". 我的应用程序似乎没有收到我发送给它的通知,使用azure站点内的调试模式,发送了测试通知,我一直试图通过一些也不起作用的.net代码发送通知,这似乎是我的通知集线器正在接收这些通知,但我的电话上的应用程序未打开,互联网正在运行,USB调试已打开,并且我没有收到显示“收到herpderp通知”的日志。

i have successfully registered my app in the notification hub, and is awaiting response with the following code: 我已经在通知中心成功注册了我的应用,并正在等待以下代码的响应:

  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();

the registerWithGcm() method: 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 class(that i give the notificationHandler as parameter): 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());
}

} }

and last(my androidManifest just the show permissions): 最后(我的androidManifest只是显示权限):

    <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>

My surgestion is to assume that my scripting on the server side is correct, and that the my GCM / Azure API keys/settings are all correct. 我的主要目的是假设我在服务器端的脚本是正确的,并且我的GCM / Azure API密钥/设置都正确。 Obviously my Notification hub receives as it's suppose to, but it seems that GCM either doesn't deliver to the registered device, or that the device does get the notification, but doesn't handle it correctly. 显然,我的通知中心收到了应有的通知,但似乎GCM未能传递到已注册的设备,或者该设备确实收到了通知,但未正确处理它。

I would thank any1 who would want to read through all this to give a qualifed guess a HUGE thanks, ive really been struggleing with this. 我要感谢任何想通读所有这本书的人,以给出有资格的猜测,非常感谢,我一直在为此苦苦挣扎。

Thanks. 谢谢。

In your registerWithGcm() method after lines 在您的registerWithGcm()方法之后

registrationId = gcm.register(SENDER_ID);
Log.i(TAG, "Registered with id: " + registrationId);

add this: 添加:

hub.register(registrationId);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM