我在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>
答案 0 :(得分:2)
首先,它肯定不是urbanairship库的问题。因为urbanairship不会错过这个基本的东西。 查看Custom Handling of Push Events
此处,通过检查PushManager.ACTION_NOTIFICATION_OPENED
然后调用UAirship.shared().getApplicationContext().startActivity(launch);
在ti.modules.titanium.urbanairship.IntentReceiver
中
public class IntentReceiver extends BroadcastReceiver {
private static final String logTag = "PushSample";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {
Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));
logPushExtras(intent);
Intent launch = new Intent(Intent.ACTION_MAIN);
launch.setClass(UAirship.shared().getApplicationContext(), MainActivity.class);
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
UAirship.shared().getApplicationContext().startActivity(launch);
}
}
您可以在launch.setClass(UAirship.shared().getApplicationContext(),
MainActivity.class );
答案 1 :(得分:1)
这可能是urbanairship图书馆的一个问题。如果他们没有在通知中添加PendingIntent,则无法打开您的应用。
我只是看了一下urbanairship.com,但似乎他们没有提供Android的源代码,只有jar。