如何添加聲音到一個notification中,這個notification是通過NotificationCompat.Builder創建的。我在res中創建了一個原始文件夾,然後添加了聲音。那麼現在如何把聲音添加到notification中?
有關 Notification 代碼:
int NOTIFY_ID=100;
Intent notificationIntent = new Intent(this, Notification.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.notification)
.setContentTitle("Warning")
.setContentText("Help!")
NotificationManager mgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, mBuilder.build());
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this);
Notification notification = mBuilder.build();
notification.sound = Uri.parse("your path");