[英]Flutter Notification custom sound not working in release mode in android
以下代码不适用于发布模式 flutter。
AndroidNotificationChannel channel= const AndroidNotificationChannel(
'abc',
'abc_channel',
description: 'This channel is used for important notifications.',
sound: RawResourceAndroidNotificationSound('alert'),
playSound: true,
importance: Importance.high,
enableLights: true,
);
please put below code in your MainActivity.java file in android folder.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
Uri soundUri=Uri.parse("android.resource://"+getApplicationContext()
.getPackageName() + "/" + R.raw.alert);
AudioAttributes audioAttributes =AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.build();
NotificationChannel channel = new
NotificationChannel("channelId","channelName",
NotificationManager.IMPORTANCE_HIGH);
channel.setSound(soundUri, audioAttributes);
NotificationManager notificationManager =
getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
并将您的自定义声音 mp3 文件放入您的项目 android/app/src/raw/mp3 文件中
Note: it will only work for Android custom sound
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.