簡體   English   中英

Flutter:本地通知自定義聲音不起作用

[英]Flutter: local notifications custom sound doesn't work

我正在嘗試為我的通知播放我自己的自定義聲音。 但是在我的 android 模擬器上,它只播放默認聲音,而在我自己的設備上,它甚至不發出聲音。 我試過這個,但它沒有幫助我。


FlutterLocalNotificationsPlugin _notifications = FlutterLocalNotificationsPlugin();

var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(initializationSettingsAndroid, initializationSettingsIOS);
await _notifications.initialize(initializationSettings);
var androidPlatformChannelSpecifics = AndroidNotificationDetails('test_channel', 'test', '', playSound: true, sound: RawResourceAndroidNotificationSound('my_sound'));
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await _notifications.show(0, 'test', 'this is a test', platformChannelSpecifics);

我沒有收到任何錯誤。 我的文件在 android/app/src/main/res/raw/my_sound.mp3

簡單的修復。 您必須完全卸載並重新安裝該應用程序,而不僅僅是更新它,您第一次安裝的通知設置將保留,因此如果它曾經設置為默認聲音。 如果您不更改頻道 ID,這將持續存在。 更多信息在這里

根據文檔:“對於 Android 8.0 或更高版本,此(聲音)與指定的通道相關聯,並且在第一次創建通道后無法更改。”

因此,要么創建一個單獨的頻道,要么只是卸載應用程序以刪除通知頻道並重新安裝它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM