1

我在我的 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>
4

2 回答 2

2

首先,这肯定不是urbanairship图书馆的问题。因为 urbanairship 不会错过这种基本的东西。检查推送事件的自定义处理

在这里,通过检查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);
    }
}

您可以在MainActivity.class中设置要启动的活动launch.setClass(UAirship.shared().getApplicationContext(),);

于 2012-10-05T19:10:43.507 回答
1

这可能是urbanairship图书馆的问题。如果他们没有在通知中添加 PendingIntent,它将不会打开您的应用程序。

我只是看了urbanairship.com,但似乎他们没有提供Android的源代码,只有jar。

于 2012-10-01T12:17:10.537 回答