开发者社区 问答 正文

应用研发平台EMAS中如何android 推送声音?

应用研发平台EMAS中如何android 推送声音?

展开
收起
真的很搞笑 2023-12-27 09:20:44 62 分享 版权
1 条回答
写回答
取消 提交回答
    • 在你的应用程序中集成EMAS的推送SDK。

      • 在接收到推送消息时,解析消息内容并创建一个Notification对象。

      • 设置Notification的属性,包括标题、内容、图标等,并指定声音资源文件。

        示例代码如下:

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID)
              .setSmallIcon(R.drawable.notification_icon)
              .setContentTitle("New Push Message")
              .setContentText(messagePayload)
              .setPriority(NotificationCompat.PRIORITY_HIGH);
        
        // 设置声音
        Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.notification_sound);
        builder.setSound(soundUri);
        
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
        notificationManager.notify(notificationId, builder.build());
        
    2023-12-29 10:14:46
    赞同 展开评论