![](/img/trans.png)
[英]pushwoosh Custom Push Broadcast Receiver not fire when application is close
[英]PushWoosh - add custom broadcast receiver
我要实现的目标:收到PushWoosh通知后,检查有效负载并将用户相应地定向到特定活动。
我正在“ PushWoosh常见问题”部分中有关以下内容的示例中
在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);
}
}
来自PWBroadcastReceiver的远程意图过滤器,您不需要它。
我的AndroidManifest.xml中没有任何中继标记
您需要将接收者名称添加到AndroidManifest.xml的元数据标记中,否则SDK不知道将推送通知路由到何处。
<receiver android:name=".receivers.PWBroadcastReceiver" />
<meta-data android:name="PW_NOTIFICATION_RECEIVER" android:value=".receivers.PWBroadcastReceiver"/>
更新 :请注意,
PW_NOTIFICATION_RECEIVER
期望package + [path to your notification receiver class]
..如果您使用的application_id(com.myapp.staging)与原始软件包名称(com.myapp)不同,则可能会导致问题。解决的方法是使用原始软件包而不是应用程序ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.