locked
Calling CreatePushNotificationChannelForApplicationAsync from a console application

    Question

  • I'm trying to figure out how to get a Push Notification Channel Uri without the user running the Windows 8 store app. All the examples I've found for getting a Channel via CreatePushNotificationChannelForApplicationAsync and sending it to a backend server show this happening *after* the user runs the application. I need to send a Push Notification to the user and I can't without the Push Notification channel Uri. I have a windows service that I'd like to use to get a Channel Uri and send it to the backend server so that I can use it to send a Push Notification to that user.

    When I try

    var channel = PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(appId).GetResults();

     from the windows service using the appId that I set in the Windows 8 store app's package.appxmanifest I get an exception of:

     System.InvalidOperationException was caught
      HResult=-2147483634
      Message=A method was called at an unexpected time.
    
    A method was called at an unexpected time.
    
      Source=""
      StackTrace:
           at Windows.Foundation.IAsyncOperation`1.GetResults()
           at PushNotificationReg.GetNotificationChannel() in c:\Users\StartupApp\PushNotificationReg.cs:line 16
      InnerException: 
    
      

    Does anyone have a solution for getting the Channel Uri when the Windows 8 store app is installed, but hasn't been run? I've looked at background and maintenance tasks, they also look like the app needs to be run in order to register them.

    Thanks for any help or direction,

    -Robert

    Monday, August 18, 2014 5:52 PM

Answers

  • Hi Robert,

    This isn't possible. The channel needs to be opened from the app's context. The app needs to run at least once to open the channel before it can receive push notifications.

    Depending on your scenario there may be other options such as updating tiles via pulling from a URI or for a app included in the OS image (I think) you can set it to automatically run once on user initialization. This is how OEM systems initialize Mail and I believe that enterprise images can use the same feature. The Windows 8.1 Installation, Setup, and Deployment forum on TechNet is probably the best place to ask about that.

    --Rob

    Tuesday, August 19, 2014 12:19 AM
    Owner

All replies

  • Hi Robert,

    This isn't possible. The channel needs to be opened from the app's context. The app needs to run at least once to open the channel before it can receive push notifications.

    Depending on your scenario there may be other options such as updating tiles via pulling from a URI or for a app included in the OS image (I think) you can set it to automatically run once on user initialization. This is how OEM systems initialize Mail and I believe that enterprise images can use the same feature. The Windows 8.1 Installation, Setup, and Deployment forum on TechNet is probably the best place to ask about that.

    --Rob

    Tuesday, August 19, 2014 12:19 AM
    Owner
  • Thanks for the feedback. Is it possible to call the Windows 8 Store app with command line parms that would cause it to just register the channel and tell the calling program what the Uri is, or send it to a web API, without it launching to the foreground and showing any UI and just exit?


    Also is there anyway to get the device ID from a windows service?

    var deviceId = HardwareIdentification.GetPackageSpecificToken(null);

    That way if the Windows 8 Store app sent the Channel Uri to the Web Service with the deviceId then the Windows Service could use the deviceID to find the Channel Uri that was stored by the Web Service.

    Thanks,

    -Robert



    Tuesday, August 19, 2014 3:33 AM
  • No, there's no way to launch an app silently. The deviceID is package specific and not valid from an external service.

    Tuesday, August 19, 2014 7:07 PM
    Owner
  • Is it possible to send a raw broadcast push notification to a Windows 8 Store app even if the app has never been run or registered for a Channel? If so can I use that to trigger the app in the background to create a Channel and send it to a Web API along with its deviceId?

    It seems odd that I could download say a Windows 8 Store News application and it can't send me any push notification alert until I run the application.

    There aren't any pre/post Windows 8 Store app installation tasks that can be used when someone downloads and installs an application?

    Thanks for you help,

    -Robert

    Tuesday, August 19, 2014 7:22 PM
  • This isn't possible. The channel needs to be opened from the app's context. The app needs to run at least once to open the channel before it can receive push notifications.

    Tuesday, August 19, 2014 8:19 PM
    Owner