在Android外面的Activity上处理`onNewIntent`

时间:2017-01-24 08:40:52

标签: android firebase push-notification firebase-cloud-messaging

我正在使用Firebase Cloud Messaging API处理推送通知相关功能的Android库。大多数将使用此库的应用程序将主要活动中的launchMode设置为singleTasksingleInstance,因此我无法获取消息信息使用对Activity getIntent的引用的背景,因为我只是引用Activity,我无法覆盖onNewIntent

当用户点按推送通知时,我有什么方法可以访问发送到应用程序的Intent吗?我尝试使用没有过滤器的IntentService,但它似乎没有抓住任何东西。

提前致谢!

1 个答案:

答案 0 :(得分:0)

我已经解决了我的问题,所以其他人可能感兴趣的解决方案:

我在清单中注册了BroadcastListener,如下所示:

    <receiver
        android:name=".MyPushNotificationReceiver"
        android:permission="com.google.android.c2dm.permission.SEND"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
        </intent-filter>
    </receiver>

有了这个,我可以在前台,后台甚至当应用程序根本没有运行时接收传入推送通知的意图。