2015-08-17 59 views
1

我想要實現的:在接收到PushWoosh通知後,檢查有效負載並相應地指導用戶進行特定的活動。PushWoosh - 添加自定義廣播接收器

我按照PushWoosh FAQ section關於

使用自定義Android中推進廣播接收機

然而一個例子,我無法接受我的自定義推送內的任何推..

這裏的AndroidManifest.xml

 <receiver 
      android:name="com.google.android.gcm.GCMBroadcastReceiver" 
      android:exported="true" 
      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="${applicationId}" /> 
      </intent-filter> 
     </receiver> 

     <receiver android:name=".receivers.PWBroadcastReceiver"> 
      <intent-filter> 
       <action android:name="${applicationId}.com.arellomobile.android.push.REGISTER_BROAD_CAST_ACTION"/> 
      </intent-filter> 
     </receiver> 
     <service android:name="com.arellomobile.android.push.PushGCMIntentService" /> 

這是我的自定義廣播接收器:

public class PWBroadcastReceiver extends BroadcastReceiver { 

    private static final String TAG = "PWBroadcastReceiver"; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (intent == null) 
      return; 

     // Let Pushwoosh SDK to pre-handling push (Pushwoosh track stats, opens rich pages, etc.). 
     // It will return Bundle with a push notification data 
     Bundle pushBundle = PushManager.preHandlePush(context, intent); 
     if (pushBundle == null) 
      return; 

     // Get push bundle as JSON object 
     JSONObject dataObject = PushManager.bundleToJSON(pushBundle); 

     // Get default launcher intent for clarity 
     Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()); 
     launchIntent.addCategory("android.intent.category.LAUNCHER"); 

     launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 

     // Put push notifications payload in Intent 
     launchIntent.putExtras(pushBundle); 
     launchIntent.putExtra(PushManager.PUSH_RECEIVE_EVENT, dataObject.toString()); 

     // Start activity! 
     context.startActivity(launchIntent); 

     // Let Pushwoosh SDK post-handle push (track stats, etc.) 
     PushManager.postHandlePush(context, intent); 
    } 
} 

回答

0
  1. 從PWBroadcastReceiver遠程意圖過濾器,你不需要它。

  2. 我沒有看到你的AndroidManifest.xml中任何meta標籤

您需要接收器名稱添加到元數據標記AndroidManifest.xml中,否則SDK不知道在哪裏路線推送通知。

<receiver android:name=".receivers.PWBroadcastReceiver" /> 
<meta-data android:name="PW_NOTIFICATION_RECEIVER" android:value=".receivers.PWBroadcastReceiver"/> 

UPDATE: 注意,PW_NOTIFICATION_RECEIVER期待package + [path to your notification receiver class]。如果您使用APPLICATION_ID(com.myapp.staging)從原始包名稱(com.myapp)不同,這可能會導致問題。 。修復方法是使用原始包而不是應用程序ID