ʕ ᵔᴥᵔ ʔ
ʕ ᵔᴥᵔ ʔ

Reputation: 792

Set up urban airship push notifications with phonegap on android

I have a PhoneGap / Cordova app, and would like to add push notifications using the urban airship plugin for PhoneGap. It looks promising. I try following the instructions from Urban Airship and look at the example at GitHub. The problem is that I am a html5-css3-JavaScript developer, not a Java / Android developer. I'm using Eclipse.

I changed the AndroidManifest.xml file like in the example, putting my package name where appropriate.

I imported the .java files PushNotificationPlugin.java, IntentReceiver.java and MainApplication.java into my project tree in the src folder. Now errors appear, for example "The import com.urbanairship.UAirship can not be resolved".

See the screenshow below for my progress so far and for the errors.

enter image description here

My questions are:

"Install the PushNotificationPlugin.java and IntentReceiver.java files into your Android project." Where do I have to place these files in the project tree, and do I have to link to them in any way? Should I also install the file MainApplication.java somewhere and how?

"Initialize the Urban Airship library in your Application class" Which file in my PhoneGap project tree is the Application class and where in this file can I copy-paste the Urban Airship code?

"Instrument your main Activity class" I have to add those few lines of Java to the Cordova main activity. Which file contains the Cordova main activity and where in this file can I copy-paste that so much desired Urban Airship code?

Any help would be greatly appreciated! I'll even build you a simple Sencha Touch app if you help me get this working...

Upvotes: 1

Views: 3499

Answers (1)

Raphael
Raphael

Reputation: 1076

I had trouble setting it up too. This is what I did to finally get it working, in complement to what is said in this tutorial:

  1. copy the urbanairship[...].jar file in the libs folder of your project (this missing file is why you have errors on your printscreen)
  2. import the MainApplication.java, IntentReceiver.java files in your main package (come.waywayway.easyapp). Update the package names in those files. I also had to replace ACTION_LOCATION_SERVICE_BOUND with ACTION_SUFFIX_LOCATION_SERVICE_BOUND in IntentReceiver
  3. import the PushNotificationPlugin.java file in a com.urbanairship.phonegap.plugins package (place it in src/com/urbanairship/phonegap/plugins), update the IntentReceiver import with your package name, and make sure to link to the plugin in res/xml/config.xml, e.g.:

    <plugin name="PushNotificationPlugin" value="com.urbanairship.phonegap.plugins.PushNotificationPlugin"/>
    
  4. update your main activity class(easyapp.java) to match the sample app main activity class (UAPhonegapSample.java)
  5. import and update your airship.properties and location.properties files as explained in the tutorial
  6. Based on the sample app AndroidManifest.xml file, update yours. Don't forget to add android:name=".MainApplication" as an attribute to the application object

Once this is done, you should be able to send a test notification from urban airship console. Your device APID should show up in Eclipse console when you launch your app. You don't need the Javascript files if you just want to be able to receive notifications.

Upvotes: 3

Related Questions