Urban Airship Android Client - Helium Push
今天说说怎样来创建一个最简单的可以接收Urban AirShip通知的Android应用程序。
1. 首先创建一个Android应用,这里需要注意的是Android应用的package名必须和Urban AirShip上application的package名一致。
2. 添加urbanairship-lib-2.0.1.jar到libs目录下,并将其加入工程的classpath中。
3. 修改AndroidManifest.xml文件,内容类似如下
[html]
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="urbanairship.client"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:name="urbanairship.client.MyApplication"
android:enabled="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.urbanairship.CoreReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
</receiver>
<service
android:name="com.urbanairship.push.PushService"
android:label="Push Notification Service"
android:process=":com.urbanairship.process" />
<service
android:name="com.urbanairship.push.PushWorkerService"
android:label="Push Notification Worker Service"
android:process=":com.urbanairship.process" />
<service
android:name="com.urbanairship.易做图ytics.EventService"
android:label="Event Service"
android:process=":com.urbanairship.process" />
<service android:name="com.urbanairship.push.PushService" />
<receiver android:name="urbanairship.client.IntentReceiver" />
<provider
android:name="com.urbanairship.UrbanAirshipProvider"
android:authorities="urbanairship.client.urbanairship.provider"
android:exported="false"
android:multiprocess="true" />
</application>
</manifest>
4. 在assets目录下创建airshipconfig.properties文件,内如如下:
[plain]
developmentAppKey = Your Development App Key
developmentAppSecret = Your Development App Key
productionAppKey = Your Production App Key
productionAppSecret = Your Production Secret
#transport is "gcm" or "helium".
transport = helium
#gcmSender = GCM sender ID
#Your GCM sender ID is your Google API project ID (required for GCM)
inProduction = false
iapEnabled = false
# 2 = Log.VERBOSE; 3 = Log.DEBUG; 4 = Log.INFO;
# 5 = Log.WARN; 6 = Log.ERROR; 7 = Log.ASSERT;
developmentLogLevel = 3
productionLogLevel = 6
注意替换其中developmentAppKey和developmentAppSecret值(可以从Urban AirShip中创建的Application下获取)
5. 修改res/values/strings.xml文件,先加入几个值,后面会用到
[html]
<resources>
<string name="app_name">urbanairship-client</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="enable_push"
补充:移动开发 , Android ,