我正在将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进行的Push Notification拦截在旧版本的库中确实起作用。现在,所有内容都已按照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 -->

最佳答案

当意向接收器扩展了基本意向接收器但在不调用super的情况下覆盖onReceive,包名称被混淆为类别或应用程序未声明并使用“ 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" />

关于android - Android Urban Airship 6.0.1,无法拦截推送通知操作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29678344/

10-10 23:51