简体   繁体   中英

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

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:

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

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

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

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

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

add this:

hub.register(registrationId);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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