Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Urban Airship Push Notifications For Mono

CodeMonkeyCodeMonkey GBMember ✭✭✭
edited October 2012 in Xamarin.Android

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

Posts

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

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

  • MichaelBluesteinMichaelBluestein USInsider, University, Developer Group Leader ✭✭✭

    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.

  • OldRedthOldRedth USMember, Insider ✭✭✭

    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

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

  • OldRedthOldRedth USMember, Insider ✭✭✭

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    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.

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    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?

  • OldRedthOldRedth USMember, Insider ✭✭✭

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

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

  • OldRedthOldRedth USMember, Insider ✭✭✭

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

  • OldRedthOldRedth USMember, Insider ✭✭✭

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

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

  • OldRedthOldRedth USMember, Insider ✭✭✭

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

  • [Deleted User][Deleted User] Xamurai
    edited October 2012

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    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.

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

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

  • OldRedthOldRedth USMember, Insider ✭✭✭

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    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.

  • OldRedthOldRedth USMember, Insider ✭✭✭

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

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

    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

  • GerryHighGerryHigh USBeta ✭✭✭

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

    Gerry

  • CodeMonkeyCodeMonkey GBMember ✭✭✭

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

  • ChrisBramleyChrisBramley USMember ✭✭

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

    Chris

  • GerryHighGerryHigh USBeta ✭✭✭
    edited July 2013

    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.

    Gerry

  • ChrisBramleyChrisBramley USMember ✭✭

    @GerryHigh Thank you, that's absolutely brilliant!

Sign In or Register to comment.