【问题标题】:Android Urban Airship 6.0.1, not able to intercept push notification actionsAndroid Urban Airship 6.0.1,无法拦截推送通知操作
【发布时间】:2015-04-16 14:49:40
【问题描述】:

我将BaseIntentReceiver 扩展为一个新类PushIntentReceiver,旨在对推送通知对象中的键/值对采取不同的操作。

虽然我的推送通知显示正确,但 PushIntentReceiver 永远不会被调用。因此,单击通知似乎无济于事。每个方法里面都有一个日志标签,比如

@Override
protected void onBackgroundPushReceived(Context context, PushMessage message) {
    Log.i(TAG, "Received background push message: " + message);
}

但这些都没有出现在 LogCat 中。不管是注册方式,还是通知点击方式什么的。同样,我的断点不会在这些函数中命中。

这是为什么?我已经包含了我的 AndroidManifest 的相关部分。这个应用程序中之前的 UrbanAirship 版本是当你们第一次创建 Amazon UA 时,Amazon UA 从 Android UA 中分离出来的版本。所以我不知道那是 Android UA 5.0 还是 4.x,但我通过 BroadcastReceivers 拦截的推送通知确实在那个旧版本的库中工作。现在一切都被重组为 UA 5.1.x+ 的方式,我无法让它工作。

洞察力赞赏

这是我AndroidManifest.xml的相关部分

<!-- REQUIRED for Urban Airship -->
    <service
        android:name="com.urbanairship.push.PushService"
        android:label="Push Notification Service" />

    <!-- Required for analytics -->
    <service
        android:name="com.urbanairship.analytics.EventService"
        android:label="Event Service" />

    <!-- Required for Actions -->
    <service android:name="com.urbanairship.actions.ActionService" />

    <!-- Required for Rich Push -->
    <service android:name="com.urbanairship.richpush.RichPushUpdateService" />

    <!-- OPTIONAL for Urban Airship Location (for segments support) -->
    <service
        android:name="com.urbanairship.location.LocationService"
        android:label="Segments Service" />

    <!-- This is required for persisting preferences related to push and location -->
    <!-- MODIFICATION REQUIRED - Replace PACKAGE_NAME with your package name -->
    <provider
        android:name="com.urbanairship.UrbanAirshipProvider"
        android:authorities="com.myapp.app.urbanairship.provider"
        android:exported="true"
        android:multiprocess="true"
        android:permission="com.myapp.app.permission.UA_DATA" />

    <!-- OPTIONAL, if you want to receive push, push opened and registration completed intents -->
    <!-- Replace the receiver below with your package and class name -->
    <receiver
        android:name="com.myapp.app.controllers.push.PushIntentReceiver"
        android:exported="false">

        <intent-filter>
            <action android:name="com.urbanairship.push.CHANNEL_UPDATED" />
            <action android:name="com.urbanairship.push.OPENED" />
            <action android:name="com.urbanairship.push.RECEIVED" />
            <action android:name="com.urbanairship.push.DISMISSED" />


            <category android:name="com.myapp.app" />
        </intent-filter>
    </receiver>

 <receiver android:name="com.urbanairship.CoreReceiver"
        android:exported="false">

        <intent-filter android:priority="-999">
            <action android:name="com.urbanairship.push.OPENED" />

            <!-- MODIFICATION REQUIRED - Use your package name as the category -->
            <category android:name="com.myapp.app" />
        </intent-filter>
    </receiver>



    <!-- REQUIRED for PlayServiceUtils.handleAnyPlayServicesError to handle Google Play Services recoverable errors. -->
    <activity
        android:name="com.urbanairship.google.PlayServicesErrorActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    <!-- REQUIRED for GCM -->
    <receiver
        android:name="com.urbanairship.push.GCMPushReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">

        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <!-- MODIFICATION REQUIRED - Use your package name as the category -->
            <category android:name="com.myapp.app" />
        </intent-filter>
    </receiver>
    <!-- end Urban Airship tags -->

【问题讨论】:

  • 一切似乎都符合您发布的顺序。我可能需要查看您的 PushIntentReceiver、完整清单,也许还有 build.gradle 文件以找出问题所在。如果您想让它们保密,您可以将它们发送到 support@urbanairship.com。我让其他人遇到的一件事是覆盖 onReceive 而不调用 PushIntentReceiver 中的超级实现。也许检查一下。
  • @ralepinski 我两天前将这个确切的帖子发送到 support@urbanairship.com
  • @ralepinski 我根本没有覆盖 onReceive,这也没有在城市飞艇示例应用程序中完成 github.com/urbanairship/android-samples/blob/master/…
  • 您是否声明了 UA_DATA 权限?可以发一下吗?

标签: android push-notification urbanairship.com


【解决方案1】:

此类问题通常发生在 Intent 接收器扩展基本 Intent 接收器但覆盖 onReceive 而不调用 super、包名称与类别混淆或应用未声明和使用“PACKAGE_NAME.UA_DATA”时允许。 SDK 现在默认自动启动应用程序的启动器活动,但如果该部分不起作用,那么您很可能需要声明权限。

在 AndroidManifest.xml 的清单部分添加:

<permission android:name="com.myapp.app.permission.UA_DATA" android:protectionLevel="signature" />
<uses-permission android:name="com.myapp.app.permission.UA_DATA" />

【讨论】:

  • 嗯,我没有protectionLevel="signature"
  • &lt;provider android:name="com.urbanairship.UrbanAirshipProvider" android:authorities="com.myapp.app.urbanairship.provider" android:exported="true" android:multiprocess="true" android:permission="com.myapp.app.permission.UA_DATA" /&gt;
  • 我看到的是供应商,是的,我没有这些标签
  • 太棒了。很高兴我们想通了。
猜你喜欢
  • 2013-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多