发布构建 apk 或 aab 时,Flutter 本地通知自定义铃声不起作用

问题描述 投票:0回答:1

我使用 Flutter 本地通知自定义铃声在发布构建 apk 或 aab 时不起作用,这是我的代码

当我添加 keep.xml 文件时出现此错误,我试图在后台播放自定义声音

* What went wrong:
Execution failed for task ':app:shrinkReleaseRes'.
> A failure occurred while executing com.android.build.gradle.internal.transforms.ShrinkProtoResourcesAction
   > Duplicate attribute '{http://schemas.android.com/tools}keep'.
      at [row,col {unknown-source}]: [5,38]
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@layout/l_used*_c,@layout/l_used_a,@layout/l_used_b*"
    tools:keep="@drawable/*,@raw/notification"
    tools:discard="@layout/unused2" />

我正在尝试所有解决方案,但它不适用于构建发布。 我的应用程序通知声音与我通过 USB 将其安装在真实设备上。 但是当我构建并安装在我的手机中时,它不起作用,我尝试使用下面的代码在我的应用程序中播放警报声音

Future<dynamic> myBackgroundMessageHandler(RemoteMessage message) async {
  print("onBackground: ${message.notification!.title}/${message.notification!.body}/${message.notification!.titleLocKey}");
   var androidInitialize = new AndroidInitializationSettings('notification_icon');
   var iOSInitialize = new IOSInitializationSettings();
   var initializationsSettings = new InitializationSettings(android: androidInitialize, iOS: iOSInitialize);
   FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
   flutterLocalNotificationsPlugin.initialize(initializationsSettings);
   NotificationHelper.showNotification(message, flutterLocalNotificationsPlugin, true);
  _playAlarmSound();
  //await playBackgroundSoundInNativeCode();
  //Get.offNamed(RouteHelper.getInitialRoute());
}


Future<void> _playAlarmSound() async {
  AudioCache audioCache = AudioCache();
  await audioCache.play('notification.mp3');
}

flutter dart audio notifications firebase-cloud-messaging
1个回答
0
投票

你找到解决办法了吗?我也遇到同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.