我在我的 Appcelerator 项目中使用 UrbanAirship 模块来接收推送通知。我正在接收推送通知,但是当用户在其 Android 设备上单击通知中心的通知时,应用程序不会启动。虽然它在 iPhone 上。任何想法如何解决这一问题?
谢谢。
更新
下面是用于在 android 上订阅推送通知的代码
UrbanAirship = require("ti.urbanairship")
Ti.API.log "UrbanAirship.pushEnabled " + UrbanAirship.pushEnabled
Ti.API.log "UrbanAirship.pushId " + UrbanAirship.pushId
UrbanAirship.options =
PRODUCTION_APP_KEY: "XXXX"
PRODUCTION_APP_SECRET: "XXXX"
DEVELOPMENT_APP_KEY: "XXXX"
DEVELOPMENT_APP_SECRET: "XXXX"
LOGGING_ENABLED: true
UrbanAirship.addEventListener UrbanAirship.EVENT_URBAN_AIRSHIP_CALLBACK, (e) ->
Ti.API.info "UrbanAirship: Received message " + e.message
alert e.message
UrbanAirship.addEventListener UrbanAirship.EVENT_URBAN_AIRSHIP_SUCCESS, (e) ->
token = e.deviceToken
Ti.App.Properties.setString "device_token", token
Ti.API.info "UrbanAirship: Received device token " + token
UrbanAirship.addEventListener UrbanAirship.EVENT_URBAN_AIRSHIP_ERROR, (e) ->
Ti.API.info "UrbanAirship: Error " + e.error
UrbanAirship.pushEnabled = true
在服务器端:
notification = {"android" => {"alert" => message}, "apids" => android_device_tokens}
Urbanairship.push(notification)
这是tiapp.xml中的android相关代码
<property name="ti.android.debug" type="bool">true</property>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest android:installLocation="preferExternal"
android:versionCode="10" android:versionName="1.0.6"/>
<manifest>
<supports-screens android:anyDensity="false"/>
<application>
<activity
android:configChanges="keyboardHidden|orientation"
android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/>
</application>
</manifest>
</android>
下面是airshipconfig.properties
developmentAppKey = xxx
developmentAppSecret = xxx
productionAppKey = xxx
productionAppSecret = xxx
transport = c2dm
c2dmSender = xxxx@gmail.com
inProduction = true
iapEnabled = false
这是自动生成的 AndroidManifest.xml
<?xml version="1.0" ?>
<manifest android:installLocation="preferExternal" android:versionCode="10" android:versionName="1.0.6" package="com.batmanadventure" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="false"/>
<uses-sdk android:minSdkVersion="8"/>
<permission android:name="com.batmanadventure.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<application android:debuggable="false" android:icon="@drawable/appicon" android:label="BatmanAdventure" android:name="BatmanadventureApplication">
<activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/>
<receiver android:name="com.urbanairship.CoreReceiver">
<!-- REQUIRED IntentFilter - For Helium and Hybrid -->
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.ACTION_SHUTDOWN"/>
</intent-filter>
</receiver>
<receiver android:name="com.urbanairship.push.c2dm.C2DMPushReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive the actuggal message -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="com.batmanadventure"/>
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.batmanadventure"/>
</intent-filter>
</receiver>
<service android:name="com.urbanairship.push.PushService"/>
<receiver android:name="ti.modules.titanium.urbanairship.IntentReceiver"/>
<activity android:configChanges="keyboardHidden|orientation" android:label="BatmanAdventure" android:name=".BatmanadventureActivity" android:theme="@style/Theme.Titanium">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiTranslucentActivity" android:theme="@android:style/Theme.Translucent"/>
<activity android:configChanges="keyboardHidden|orientation" android:name="org.appcelerator.titanium.TiModalActivity" android:theme="@android:style/Theme.Translucent"/>
<activity android:configChanges="keyboardHidden|orientation" android:name="ti.modules.titanium.ui.TiTabActivity"/>
<activity android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"/>
<service android:exported="false" android:name="org.appcelerator.titanium.analytics.TiAnalyticsService"/>
</application>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.batmanadventure.permission.C2D_MESSAGE"/>
</manifest>