2017-03-09 91 views
0

我用onesignal向我的应用程序发送通知。当我发送通知并将其打开时,该应用完美无缺。不幸的是,即使我设置了广播接收器,该应用在关闭时也不会收到通知当应用程序关闭时收到通知

<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" /> 
+0

请检查这个答案类似于您的问题[?当应用程序被关闭如何获得Android通知] (http://stackoverflow.com/questions/13741875/how-to-get-android-notifications-when-app-was-closed) – Shahrukh

回答

0

添加

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

到GcmBroadcastReceiver

而且

<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.GcmBroadcastReceiver" 
    <permission android:name="<your app package>.permission.C2D_MESSAGE" 
     android:protectionLevel="signature" /> 
    <uses-permission android:name="<your app package>.permission.C2D_MESSAGE" /> 
</receiver> 

取决于GCM BroadcastReceiver fired only when app is running or running at background

1

只是使接收机类扩展WakefulBroadcastReceiver并在清单中添加以下行:

<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> 
相关问题