我们与 localytics 团队就如何集成 localytics 来发送和接收推送通知进行了长时间的讨论。我正在分享工作解决方案。
文档 ( http://docs.localytics.com/ )中提到的 PROJECT_NUMBER与 SENDER_ID 相同。
还假设您遵循自动集成,如果您希望知道针对高级部分中的键发送的值(可选)(可能是深层链接 url),您需要编写自己的自定义接收器扩展 com.localytics.android .PushReceiver,也在清单中定义它。
该值可以在您的自定义接收器的 onReceive 中作为 intent.getExtras().getString("key") 访问。
不要忘记初始化默认构造函数并在 onReceive 中调用 super.onReceive(context,intent)。
public class CustomReceiver extends PushReceiver {
private static final String TAG = PushReceiver.class.getSimpleName();
public CustomReceiver()
{
super();
}
@Override
public void onReceive(Context context, Intent intent)
{
super.onReceive(context,intent);
Log.i(TAG, intent.getExtras().getString("key"));
}
}
<receiver
android:name="yourpackagename.receivers.CustomReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="yourpackagename"/>
</intent-filter>
</receiver>