我通过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);
}
在这里我可以放置通知声音的详细信息吗?我已经尝试了Notification.Sound成员,但它要求提供一个我没有引用的uri。
答案 0 :(得分:0)
如果要播放自定义通知声音,请添加此项
notification.sound = Uri.parse("android.resource://" + context.getPackageName() + "your_sound_file_name.mp3");
答案 1 :(得分:0)
在功能激活的默认通知声音中添加此行代码。
notification.Defaults = NotificationDefaults.Sound;