Urban Airship Logo

Urban Airship is a popular messaging and notification service. In this post we’ll look at how to set up Urban Airship push notifications. The eventual goal is to use these notifications to trigger replications in Couchbase Mobile.

What you’ll need

You can use Urban Airship (UA) for free. (See the UA web site for current pricing details.) You do have to register an account.

  • An Urban Airship account
  • A Firebase account (requires a Google Login account)
  • Android Studio (or Xcode)

Setting up

Bring up an existing Android or iOS project in your IDE (or create a new one). Here I’ll illustrate using Android.

Sign in to your UA account. Navigate to the New App page. Fill in your app name. Select the platforms you want to use. (We’ll pick Android and iOS for this example.) Hitting “Save” will take you to the quickstart quide.  (If you’ve already gone through the quickstart and need a refresher on the setup, you can find the steps for Android here and for iOS here.)

Urban Airship New Application Dialog

UA quickstart

Here you’re offered a tab for each platform selected. As mentioned, we’ll focus on building for Android this time.

Follow the Urban Airship quickstart steps. I have a few tips for issues I encountered.

Steps 1 & 2

The UA guide refers to the project’s build.gradle script, but then shows modifying the module build.gradle script. I added the UA repository to my project’s gradle script, and the UA dependency to the module gradle script. That worked fine.

Look for the applicationID in the module gradle script.

Step 5

To create your own Application class, right click in the app area of the Project navigation pane and pick New > Java Class. In the popup, set the class name. Then for the Superclass enter android.app.Application.

Creating an Application subclass

Don’t forget to update your manifest file. You can use the fully qualified name of your class, or the short form that UA shows. The fully qualified form looks like this:

Step 6

UA uses Firebase Cloud Messaging (FCM). Step six has a link to further documentation by UA. This new page has detailed instructions on creating an API key for your app.

The instructions on that page under the heading ‘Configure FCM/GCM Service with Urban Airship’ are a little out of date. You’ll find the area to enter your Api Key and Package at the end of the quickstart guide now, instead of where the docs say to look.

In one place, the UA docs refer to the “Google API Project Number”. This is what FCM calls your Sender ID.

Testing

The quickstart ends with a testing area, without much instruction. If you look back at the code included in your Application subclass, you’ll see it’s enabling user notifications. To test, build your app and install it on an emulator or device. (I tried both and they worked fine.)

Urban Airship Test Panel

Enter something into the text field and click “Send Test”. You should see an icon show up in the Android notification area. Oddly, this doesn’t include the text entered into the test area.

For troubleshooting UA directs you to an obscure “Error Console” link in the lower right corner of the documentation page. The link just brought me back to the quickstart guide, unfortunately.

Wrapping up

In the end setting up Urban Airship was pretty quick. The quickstart shows how to send an alert notification. To trigger data sync in a Couchbase Lite client, we’ll want to send a silent alert instead. That’ll be the subject of a future post.

Postscript

If you liked the article, check out Couchbase Mobile, the most powerful mobile + sync database stack available. Follow along here on the Couchbase Blog site while we build out this and other examples.

Find more resources on our developer portal and follow us on Twitter @CouchbaseDev.

You can post questions on our forums. And we actively participate on Stack Overflow.

You can follow me personally at @HodGreeley

Posted by Hod Greeley, Developer Advocate, Couchbase

Hod Greeley is a Developer Advocate for Couchbase, living in Silicon Valley. He has over two decades of experience as a software engineer and engineering manager. He has worked in a variety of software fields, including computational physics and chemistry, computer and network security, finance, and mobile. Prior to joining Couchbase in 2016, Hod led developer relations for mobile at Samsung. Hod holds a Ph.D. in chemical physics from Columbia University.

One Comment

Leave a reply