1

I used onesignal to send notification to my app. The app work perfect when I send notification and its open. Unfortunately the app not receive notification when it closed even I set broadcast receiver.

<receiver
        android:name="com.onesignal.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>
 <receiver android:name="com.onesignal.BootUpReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter>
    </receiver>
<service android:name="com.onesignal.GcmIntentService" />
    <service
        android:name="com.onesignal.SyncService"
        android:stopWithTask="false" />
Nada Feteiha
  • 61
  • 1
  • 2
  • 7
  • Please check this answer similar to your question [How to get android notifications when app was closed?](http://stackoverflow.com/questions/13741875/how-to-get-android-notifications-when-app-was-closed) – Shahrukh Mar 09 '17 at 11:30

2 Answers2

1

Just make the receiver class extend WakefulBroadcastReceiver and add the following lines in your manifest :

<receiver android:name=".YOUR_RECEIVER_CLASS"
       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"/> 
    <category android:name="com.example.gcm"/>
</intent-filter>
</receiver>
R.R.M
  • 780
  • 4
  • 10
0

add

        <action android:name="android.intent.action.BOOT_COMPLETED" />
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />

to GcmBroadcastReceiver

And

<receiver
        android:name="com.onesignal.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>

should be

<receiver
        android:name="com.onesignal.GcmBroadcastReceiver"
    <permission android:name="<your app package>.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="<your app package>.permission.C2D_MESSAGE" />
</receiver>

depends on GCM BroadcastReceiver fired only when app is running or running at background

Community
  • 1
  • 1
Andrey Danilov
  • 6,194
  • 5
  • 32
  • 56