通过Android设备使用GCM服务没有通知声音



我正在通过GCM服务向android设备发送通知。向客户端发送消息不是问题,问题在于当手机收到通知时没有播放声音。

我在客户端(mono android)使用以下代码来构建通知请求

void createNotification(string title, string desc)
     {
       //Create notification
       var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
    //Create an intent to show ui
    var uiIntent = new Intent(this, typeof(Main));
    //Create the notification
    var notification = new Notification(Android.Resource.Drawable.SymActionEmail, title);
    //Auto cancel will remove the notification once the user touches it
    notification.Flags = NotificationFlags.AutoCancel;
    //Set the notification info
    //we use the pending intent, passing our ui intent over which will get called
    //when the notification is tapped.
    notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));
    //Show the notification
    notificationManager.Notify(1, notification);
}

我可以在这里放置通知声音播放的细节?我已经尝试了通知。声音成员,但它要求一个uri,我没有引用

如果你想播放自定义通知声音,添加这个

  notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");

在函数激活默认通知声音中添加这行代码。

notification.Defaults = NotificationDefaults.Sound;

最新更新