我正在使用MixPanel发送推送通知,并在自定义负载中添加以下代码: {"sound":"default"} 问题是当我收到通知时没有声音播放。是否有人有解决方案?
我正在使用MixPanel发送推送通知,并在自定义负载中添加以下代码: {"sound":"default"} 问题是当我收到通知时没有声音播放。是否有人有解决方案?
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
add the following code to the onCreate:
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this);
mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
Send notification from mixpanel and see it received. This will send notification on create with default sound configured on the user's device.
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
.setTicker(title)
.setWhen(ts)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentText(message);
final String ringTone = "default ringtone"; // or store in preferences, and fallback to this
mBuilder.setSound(Uri.parse(ringTone));
Notification notification = new Notification(R.drawable.appicon,
"Notification", System.currentTimeMillis());
notification.defaults = Notification.DEFAULT_SOUND;
final Notification notification =
new Notification(iconResId, tickerText, System.currentTimeMillis());
final String packageName = context.getPackageName();
notification.sound =
Uri.parse("android.resource://" + packageName + "/" + soundResId);
Android Mixpanel库中默认的GCMReceiver处理来自Mixpanel的推送通知时不包括声音。您需要编写自己的BroadcastReceiver来处理来自Mixpanel的消息。
您可以查看Mixpanel的文档,了解使用低级API的方法:https://mixpanel.com/help/reference/android-push-notifications#advanced - 然后应用其他答案中的建议,以对自定义数据有效负载执行任何操作。