2017-04-07 90 views

回答

0

是的!这里有一个例子:

var pathToPushSound = $"android.resource://com.your.package/raw/{soundName}"; 
var soundUri = Android.Net.Uri.Parse(pathToPushSound); 
var builder = new NotificationCompat.Builder(_context) 
      .SetContentTitle("TITLE") 
      .SetContentText("TEXT") 
      .SetPriority(1) 
      .SetSmallIcon(Resource.Drawable.TransparentLogo) 
      .SetOngoing(true) 
      .SetSound(soundUri); 
builder.Build(); 

URI是路径到您的声音文件的生活,那么你设置URINotificationBuilder使用SetSound方法的资源。

+0

但是,我在哪里使用这个?这只适用于前台通知? – xyqw

+0

这就是你如何做前台和后台通知。在Android中,它们以相同的方式工作,您仍然需要调用NotificationManager来发送构建的通知。此示例代码直接来自Xamarin.Android应用程序中的推送通知处理程序。 – SuavePirate

+0

我的问题是,我还没有想通,如何调用OnMessageReceived为背景通知,所以我不知道,如何使用NotificationBulder进行背景通知。我使用Firebase,顺便说一句。 – xyqw