Today I Learned How to Handle Local Notifications in Xamarin on Android

In my previous example I detailed how to schedule notifications in Xamarin on Android but didn’t show the Xamarin Forms application reacting to that specific notification.  Let’s fix that.

First override the OnNewIntent method in the MainActivity.  We override this method so notifications will work if the application is currently running or is stopped and the notification started the application.  In the OnNewIntent method you put code that makes sure it’s a notification you want to respond to then extracts any needed information from the notification.  An example is below:

[Read More]

Today I Learned How To Create Xamarin iOS and Android Unit Tests

I’m currently working on a notification plugin for Xamarin Forms and wanted to setup some unit tests.  The problem is my code accesses the device-specific notification systems in iOS and Android.  This means I can’t just run my unit tests on Windows.  Instead I need to run the unit tests in a iOS or Android environment.  In my case this means an emulator.

How to do that?  Use the NUnit 3 Xamarin Runners.  It was not clear how to correctly create the test projects but the way that worked for me was this.

[Read More]

Today I Learned Xamarin Push Notification Plugins

I learned this week that there is no built-in support for Push Notifications in Xamarin Forms.  On the plus side there are several open source projects trying to fill this hole.  The one that has caught my eye is edsnider/Xamarin.Plugins.

It only supports local notifications but that is all I need right now.  I like it because it looks simple to use.  The only downside is it looks abandoned.  Hopefully I’ll get around to actually trying it this week.

[Read More]

Fixing MSBuild not Exiting

After upgrading to Visual Studio Xamarin 4.1 from 4.0 our TeamCity build suddenly stopped working.  Actually it was working but won’t stop working.  The build would get hang after rebuilding out solution to create the IPA file.

The step in question looked like:

Solution Runner That Hangs

The TeamCity logs looked like:

[09:23:28][Foo\Foo.iOS\Foo.iOS.csproj] _SayGoodbye
[09:23:28][_SayGoodbye] SayGoodbye
[09:23:28][SayGoodbye] Compute signature for bin\iPhone\Release\FooiOS.app

The build would also hang if I logged into the build machine and ran the msbuild via the command line.  However, the build would not hang if built via Visual Studio.

[Read More]

Connect to Android Emulator from VirtualBox

I do all my development inside virtual machines.  This allows me to keep separate development environment for different projects and clients.  I wanted to keep this tradition for developing mobile applications but that turned out to be a bit of challenge.

The Xamarin Android Player and the Genymotion emulators both use VirtualBox to emulate the Android phone or tablet.  This works great if you don’t develop in a virtual machine.  If you develop inside a virtual machine you run into a major problem:  you can’t run a virtual machine inside a virtual machine.

[Read More]