当安卓的app在后台运行时出现弹出的系统弹窗没有根据手机语言实现国际化 uni-app

当安卓的app在后台运行时出现弹出的系统弹窗没有根据手机语言实现国际化 uni-app

操作步骤:

  • 打开app,进入后台运行,通知栏弹出正在运行提示

预期结果:

  • 弹出的正在运行提示是显示手机语言。或者英文

实际结果:

  • 弹出的正在运行提示是中文

bug描述:

当安卓的app在后台运行时出现弹出的系统弹窗没有根据手机语言实现国际化, 手机是三星手机 语言设置的 uni.setLocale(‘ko’); 起因是app在后台运行是,系统弹出一个正在运行的提示框,但是app是实际使用在韩国,手机也是韩语,但是这个弹窗的内容却是中文,是缺少了啥配置吗

信息类别 详细信息
产品分类 uniapp/App
PC开发环境 Windows
PC操作系统版本 11
HBuilderX类型 正式
HBuilderX版本 4.45
手机系统 Android
手机系统版本 Android 12
手机厂商 三星
手机机型 sm-g8870
页面类型 vue
vue版本 vue2
打包方式 云端
项目创建方式 HBuilderX

Image 1 Image 2


更多关于当安卓的app在后台运行时出现弹出的系统弹窗没有根据手机语言实现国际化 uni-app的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于当安卓的app在后台运行时出现弹出的系统弹窗没有根据手机语言实现国际化 uni-app的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这个问题是由于uni-app默认的国际化配置未覆盖到系统级通知弹窗导致的。系统后台运行提示的文本由原生层控制,需要单独配置多语言资源。

解决方案:

  1. nativeplugins 目录下创建原生插件,在 AndroidManifest.xml 中添加多语言支持:
<application>
  <meta-data
    android:name="android.app.lib_name"
    android:value="uniapp" />
  <meta-data
    android:name="android.app.allow_backup"
    android:value="true" />
  <!-- 添加多语言支持 -->
  <service
    android:name="io.dcloud.feature.background.foreground.ForegroundService"
    android:foregroundServiceType="location" />
</application>
  1. 在项目根目录创建 nativeplugins/BackgroundService/Android 目录,添加对应语言的 strings.xml
  • values/strings.xml(默认英文):
<resources>
    <string name="foreground_notification_text">App is running in background</string>
</resources>
  • values-ko/strings.xml(韩文):
<resources>
    <string name="foreground_notification_text">앱이 백그라운드에서 실행 중입니다</string>
</resources>
  1. 在后台服务代码中引用国际化字符串:
Notification.Builder builder = new Notification.Builder(context)
    .setContentText(context.getString(R.string.foreground_notification_text));
回到顶部