[expo-notifications][managed workflow][EAS Build][Android] 自定义声音不在本地预定通知中播放

Posted

技术标签:

【中文标题】[expo-notifications][managed workflow][EAS Build][Android] 自定义声音不在本地预定通知中播放【英文标题】:[expo-notifications][managed workflow][EAS Build][Android] custom sound not playing in locally scheduled notifications 【发布时间】:2021-12-29 01:59:32 【问题描述】:

我正在使用自定义声音在本地安排通知,但未播放自定义声音。事实上,没有显示通知警报。即使在 setNotificationsHandler 中将 show alert 和 shouldPlaySound 设置为 true。还应该提到的是,即使我在 app.json 的 expo-notifications 插件以及通知通道和通知内容输入中添加了自定义颜色,颜色也保持不变。

我检查了安装 apk 的设备的通知设置。存在通知频道,并且该频道的默认铃声也设置为自定义声音。但是它只是在通知到来时不播放。

相关代码:

import  StatusBar  from "expo-status-bar";
import React from "react";
import  Text, View, Platform, Button  from "react-native";
import * as Notifications from "expo-notifications";

Notifications.setNotificationHandler(
  handleNotification: async () => (
    shouldShowAlert: true,
    shouldPlaySound: true,
    shouldSetBadge: false,
  ),
);

export default function App() 
  React.useEffect(() => 
    setNotificationChannelAsync();
  , []);

  return (
    <View
      style=
        flex: 1,
        alignItems: "center",
        justifyContent: "space-around",
      
    >
      <Text>This App is for Testing Notifications</Text>
      <Button
        title="Press to schedule a notification"
        onPress=async () => 
          await scheduleNotification();
        
      />
      <StatusBar style="auto" />
    </View>
  );


const setNotificationChannelAsync = () => 
  if (Platform.OS === "android") 
    Notifications.setNotificationChannelAsync("sound", 
      name: "sound notification",
      importance: Notifications.AndroidImportance.HIGH,
      vibrationPattern: [0, 250, 250, 250],
      lightColor: "#FF231F7C",
      sound: "adhan.wav",
    );
  
;

async function scheduleNotification() 
  await Notifications.scheduleNotificationAsync(
    content: 
      title: "You've got mail! ????",
      body: "Here is the notification body",
      data:  data: "goes here" ,
      sound: "adhan.wav",
      color: "#FF231F7C",
    ,
    trigger:  seconds: 5, channelId: "sound" ,
  );

以下是最小可重现示例的 github repo。 https://github.com/basit3407/testing-custom-sound-notifications

【问题讨论】:

【参考方案1】:

我认为这是因为默认通知渠道。我删除了所有频道。使用新的频道标识符设置新的新频道并开始工作。

【讨论】:

以上是关于[expo-notifications][managed workflow][EAS Build][Android] 自定义声音不在本地预定通知中播放的主要内容,如果未能解决你的问题,请参考以下文章

您好,请问java中tostring方法如何输出对象数组??

how-to-add-a-breakpoint-in-a-managed-generic-method-in-windbg-sos

[Machine Learning for Trading] {ud501} Lesson 19: 02-09 The Fundamental Law of active portfolio mana

OUTPUT INSERTED Id/SCOPE_IDENTITY() 在 C# (ASP.NET Core Razor Pages) SQL 查询中返回 null,在 SQL Server Mana

谁能告诉我所有的符文名字与序号~还有作用

firebase.initializeApp() 与 FirebaseApp.initializeApp()