简体   繁体   English

带有声音的Android Mixpanel推送通知

[英]Android Mixpanel push notification with sound

I've developed an app which uses push notifications with Mixpanel. 我开发了一个使用Mixpanel的推送通知的应用程序。 They are working well, including deep linking. 它们运行良好,包括深层链接。

The problem is that my customer want them to sound once received but they don't play any sound. 问题是我的客户希望他们在收到声音后就发出声音,但它们却不播放任何声音。

After reading the docs I know that for iOS is as easy as adding a field in the custom data, but with Android there is no sound field to customize this. 阅读文档后,我知道对于iOS而言,就像在自定义数据中添加字段一样容易,但是对于Android,没有声场可以自定义此字段。 If I'm not wrong the only solution is to extend the Mixpanel broadcast receiver, so I changed my AndroidManifest from this: 如果我没看错,唯一的解决方案是扩展Mixpanel广播接收器,因此我从中更改了AndroidManifest:

<receiver android:name="com.mixpanel.android.mpmetrics.GCMReceiver"
          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="my.package.name" />
    </intent-filter>
</receiver>

to this: 对此:

<receiver android:name=".auxiliary.LocalNotificationBroadcastReceiver"
          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="my.package.name" />
    </intent-filter>
</receiver>

And I've added this class .auxiliary.LocalNotificationBroadcastReceiver: 并且我添加了此类.auxiliary.LocalNotificationBroadcastReceiver:

import com.mixpanel.android.mpmetrics.GCMReceiver;

public class LocalNotificationBroadcastReceiver extends GCMReceiver {

    @Override
    public void onReceive(final Context context, Intent intent) {
        super.onReceive(context, intent);
    }
}

This way push notifications sent from Mixpanel are still received correctly, but I don't know how to add sound to this notification. 这样,仍然可以正确接收从Mixpanel发送的推送通知,但是我不知道如何在此通知中添加声音。

Any help would be very appreciated! 任何帮助将不胜感激!

Fork the MixPanel library and customize the notification builder. 分叉MixPanel库并自定义通知生成器。 Note the following: 请注意以下几点:

  • MixPanel uses MPConfig to get notification defaults MixPanel使用MPConfig获取通知默认值
  • MixPanel doesn't use NotificationCompat so there are several builder methods (might be because they don't include the support lib). MixPanel不使用NotificationCompat,因此有几种构建器方法(可能是因为它们不包括支持库)。

This is where they build the notification: 他们在此处构建通知:

https://github.com/mixpanel/mixpanel-android/blob/master/src/main/java/com/mixpanel/android/mpmetrics/GCMReceiver.java#L376 https://github.com/mixpanel/mixpanel-android/blob/master/src/main/java/com/mixpanel/android/mpmetrics/GCMReceiver.java#L376

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM