如何在android中设置带有通知的自定义声音
我已将notification.mp3文件放入res->raw文件夹。但当触发通知时,它会产生默认声音。我从firebase推送通知收到通知,它正在工作。 这就是我发出通知的方式如何在android中设置带有通知的自定义声音,android,android-notifications,Android,Android Notifications,我已将notification.mp3文件放入res->raw文件夹。但当触发通知时,它会产生默认声音。我从firebase推送通知收到通知,它正在工作。 这就是我发出通知的方式 Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification); NotificationCompat.Builder build
Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext, CHANNEL_ID);
builder.setCustomBigContentView(notificationLayoutExpanded);
builder.setSmallIcon(R.drawable.ic_notifications);
builder.setContentTitle(message);
builder.setSound(soundUri, AudioManager.STREAM_NOTIFICATION);
builder.setAutoCancel(true);
builder.setPriority(Notification.PRIORITY_HIGH);
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(),
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());