简体   繁体   中英

Android Mixpanel push notification with sound

I've developed an app which uses push notifications with 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. If I'm not wrong the only solution is to extend the Mixpanel broadcast receiver, so I changed my AndroidManifest from this:

<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:

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.

Any help would be very appreciated!

Fork the MixPanel library and customize the notification builder. Note the following:

  • MixPanel uses MPConfig to get notification defaults
  • MixPanel doesn't use NotificationCompat so there are several builder methods (might be because they don't include the support lib).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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