Urban Airship Push Notifications For Mono RRS feed

  • Question

  • User109 posted

    Hi all, this is a follow on thread from one I had going in the old forums, see this link: http://mono-for-android.1047100.n5.nabble.com/Trying-to-Call-PushManager-share-setIntentReciver-IntentReceiver-class-tp5712058.html

    As you can see from my last post I am now receiving the push notifications, but my IntentReciever class which overrides BroadcastReciever is not being fired when the message comes down. All I am getting is a message in my notifications area with the text I pushed down.

    Could someone shed some light on this, am I not understanding purpose of the IntentReciever class? Is it not there to override the Urban Airships built in notification reciever?

    All help appreciated! Adrian

    Thursday, October 4, 2012 9:57 AM

All replies

  • User109 posted

    Anyone? Feel like I might be the only person to have tried implementing UA with Mono :/.

    Thursday, October 4, 2012 1:55 PM
  • User16 posted

    Hi Adrian,

    I'm not familiar with Urban Airship specifically, but when a BroadcastReceiver isn't called, it's often a result of the receiver not being registered, either in the AndroidManifest.xml or by calling RegisterReceiver.

    Thursday, October 4, 2012 5:29 PM
  • User40 posted

    I'm not terribly familiar with them either, but I know they have a REST api of some sort... Can you use that to get your registration ID to them?

    Alternatively, this is a great time for me to plug PushSharp ;) https://github.com/Redth/PushSharp

    Thursday, October 4, 2012 7:21 PM
  • User184 posted

    @Redth: I'm using Pushsharp myself. Any chance the GCM flavor will become a little more flexible for integration? I had to basically leave your sample implementation in place and just comment out what I didn't need for it to work. For instance, the SampleBroadcastReceiver contains a TAG and SENDER_Id that don't seem to be used. All in all though, it was rather easy to get up and running - too bad my customer decided to go for long polls instead push in the end so now the code sits dormant.

    Thursday, October 4, 2012 9:05 PM
  • User40 posted

    @Stephan I really need to revisit the GCM client example, however I really need to also talk to @jonpryor and see if some things could be accomplished with Mono for Android that would really help me improve the GCM client story. I will make this a near term goal for PushSharp :)

    Thursday, October 4, 2012 11:28 PM
  • User109 posted

    Thanks for the comments guys.

    @mikeb - I do believe I am performing both of those steps correctly. I have the following in my Manifest:

    <receiver android:name="com.gravity.xxxIntentReciever" />

    and this JNIev call supposedly registers the receiver:

    JNIEnv.CallVoidMethod(ip_class, ip_setIntent, new JValue(Java.Lang.Class.FromType(typeof(IntentReciever))));

    I did just get the following reply from their support after I enquired about an exception I was getting on a certain device:

    Thank you for getting in touch, unfortunately it looks like you're building your app with a 3rd party provider, mono, and we don't provide support for 3rd party platforms such as this.

    I would suggest checking with their own support forums, or stackoverflow.com for further assistance.

    On the old Xamarin forums there was a a guy who enquired about getting UA working with mono, he ended that thread by saying he had got it working, but I don't know whether he was using the IntentReciever. He may have just been letting the UrbanAirship service handle the displaying of the notification which is the stage I am at.

    @Redth - I am aware of PushSharp but my employer has used UA before and he is keen to stick with it. I might have to try convince him otherwise.

    Friday, October 5, 2012 8:45 AM
  • User109 posted

    Hurrah, convinced the boss to give this PushSharp service a few days development time to test it!

    @Redth Would you recommend a windows service as an implementation method for the server side service?

    Friday, October 5, 2012 10:13 AM
  • User40 posted

    @CodeMonkey yeah a windows service would work out just fine! Just make sure you are keeping a long lasting instance of PushService around. I have had others try and create a new instance for every message they sent. Doh!

    Maybe I should add a windows service example sometime soon...

    Friday, October 5, 2012 11:16 AM
  • User109 posted

    @Redth I am setting up my PushService to use C2DM (older app), when making the call to StartAndroidPushService() I need to pass in an instance of C2dmPushChannelSettings which accepts a username and password. What do these values actually correspond to? I thought C2DM only used an email address? Is this the UN and PW for the Google API account?

    Friday, October 5, 2012 12:30 PM
  • User109 posted

    Ignore my previous post, have resolved this, I was just being a bit special.

    Friday, October 5, 2012 1:45 PM
  • User109 posted

    @Redth When sending out a large number of notifications, she each send process be placed on a new thread or should the processes be queued up and executed one at a time?

    Friday, October 5, 2012 3:14 PM
  • User40 posted

    @CodeMonkey depends how you're using PushSharp... If you use the PushService class, then you can just queue up all the notifications you want. .QueueNotification(...) is not really blocking in the sense that it will add the notification to the queue and immediately return. PushService takes care of the threading for you so you can fire and forget.

    Friday, October 5, 2012 4:06 PM
  • User40 posted

    @Stephan I've started a branch based on some theoretical improvements to Mono for Android that may or may not actually make it into a future version. If they do, the implementation will be a LOT easier for GCM on the client side. For instance, you would simply add this source file to your project: http://bit.ly/Vrgroe and customize as needed. No messing around with AndroidManifest.xml, or custom permissions, etc. The only other code other than that GcmHandler.cs would be calling GcmHandler.Register(...); where appropriate in your application (and UnRegister if need be).

    How's that look?

    Friday, October 5, 2012 4:39 PM
  • User109 posted

    @Redth Is is possible to display a Popup notification (if the app is running) when the notification is received? At the moment I use the NotificationManager class to add a new notification which is displayed in the default Android notification area, but if my app is open I would like it to actually display a popup with the message.

    I know I can display the popup with the message if the user selects the relevant notification but would like to remove this step if possible.

    I have tried using an AlertDialog Builder within my GCMBaseIntentService class but I don't think I have the right context.

    Monday, October 8, 2012 10:31 AM
  • User40 posted

    @CodeMonkey You can't directly show an AlertDialog from a service, you must do so from an Activity. So, one common way to handle this is to show an activity from your GCMBaseIntentService class and then make that activity transparent, and have it show some sort of alert within the activity (you could even show an AlertDialog, just make sure you handle finishing the activity when the dialog is closed, if that's the intent!).

    Hope that helps!

    Monday, October 8, 2012 4:29 PM
  • User81 posted

    I've used Urban Airship, but not for in Mono for Android! I can confirm that it works great on MonoTouch. I could try and write up something about it :)

    Monday, October 8, 2012 6:51 PM
  • User109 posted

    Thanks again for the replies, Redth we are just gonna stick with the regular notifications, have read that displaying popups for notifications is not a great idea.

    @pierceboggan - Would be great to see a sample of your code, in particular you IntentReciever class and how you set the UA intent reciever. I believe this is where I am running into issues.

    Tuesday, October 9, 2012 10:15 AM
  • User109 posted

    @Redth Is there a way to pass your library my list of device registration ID's or do I need to loop over them and create a new notification for each?

    Think this should maybe be moved to a new thread? Possibly even have a seperate root menu for PushSharp, that'll keep you busy!

    Tuesday, October 9, 2012 11:20 AM
  • User40 posted

    @CodeMonkey :) there is a thread in the cross platform section on PushSharp

    Anyway, right now there is no way to send a batch. You have to loop through. I should add a batching method in the future, just not much code savings for the user and may cause more confusion thinking its somehow more intricate than me just looping for you!

    Tuesday, October 9, 2012 11:22 AM
  • User109 posted

    Doh, I need to do some exploring.

    I ask because I noticed a List property called RegistrationIds but couldn't work out how to assign values to it. Will stick with my current implementation of looping over the devices.

    Tuesday, October 9, 2012 11:26 AM
  • User40 posted

    Oh if you are using GCM there is a way to batch. Since GCM actually supports batching in its protocol (up to 1000 registration ids per message).

    I may have a bug right now though since .ForRegistrationId should accept a params string[]

    Will look at fixing that today :)

    Tuesday, October 9, 2012 11:30 AM
  • User109 posted

    Yeah, we decided to switch to GCM after seeing how easy your library made implementation!

    I will start posting any questions I have in the relevant thread. Thanks again

    Tuesday, October 9, 2012 11:35 AM
  • User192 posted

    @CodeMonkey I do have a binding library to UA's 3.x jar file, and other code that works to receive the notification, etc. in case you're still interested.


    Tuesday, June 18, 2013 9:43 PM
  • User109 posted

    @GerryHigh Thanks Gerry, I think we're gonna stick with our own implementation for now but will your post in mind.

    Wednesday, June 19, 2013 8:20 AM
  • User2756 posted

    @GerryHigh Hi Gerry, I'm currently working on implementing a UA binding for monodroid. Do you have a github repo with a sample of the binding you mentioned? I'd be very grateful if I could reference a working implementation.


    Tuesday, July 16, 2013 11:28 AM
  • User192 posted

    Chris--here you go: https://github.com/gerryhigh/UrbanAirship

    Look at the UrbanAirshipBindings project. However, the sample project that is out there is of no value and so I'll have to update that. There isn't much really to that part if you follow the steps listed elsewhere.


    Tuesday, July 16, 2013 12:48 PM
  • User2756 posted

    @GerryHigh Thank you, that's absolutely brilliant!

    Tuesday, July 16, 2013 12:57 PM