uni-app 安卓通知消息没有弹窗提醒只有消息栏显示 ios正常
uni-app 安卓通知消息没有弹窗提醒只有消息栏显示 ios正常
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | Windows 11 企业版 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
PC开发环境操作系统版本号:Windows 11 企业版
HBuilderX类型:正式
HBuilderX版本号:3.98
手机系统:Android
手机系统版本号:Android 14
手机厂商:vivo
手机机型:iqooneo855
页面类型:vue
vue版本:vue2
打包方式:云端
操作步骤:
<template>
<view class="content">
<button @tap="push">发送推送</button>
<button @tap="push2">使用变量</button>
</view>
</template>
<script>
export default {
data() {
return {
title: '我是变量'
}
},
onLoad() {
},
methods: {
push() {
uni.createPushMessage({
title: '测试',
cover: false,
content: '测试',
sound: "system"
})
},
push2() {
uni.createPushMessage({
title: this.title,
cover: false,
content: this.title,
sound: "system"
})
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
预期结果:
出现悬浮通知
实际结果:
没有
bug描述:
悬浮通知已开启,但是没有悬浮通知,只有消息栏通知
3 回复
图片是全部代码
有人知道吗
在 uni-app 中,Android 设备上的通知消息没有弹窗提醒,只有消息栏显示,而 iOS 设备正常,可能是由于以下原因导致的:
1. 通知权限未正确配置
- 原因: Android 设备需要明确请求通知权限,如果权限未正确配置,通知可能只会显示在通知栏,而不会弹出提醒。
- 解决方案:
- 确保在
AndroidManifest.xml
中正确配置了通知权限:<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
- 在应用启动时,动态请求通知权限:
plus.android.requestPermissions(['android.permission.POST_NOTIFICATIONS'], function(result) { console.log('Notification permission granted:', result.granted); }, function(error) { console.error('Failed to request notification permission:', error); });
- 确保在
2. 通知渠道未正确配置
- 原因: 从 Android 8.0 (API 26) 开始,通知必须通过通知渠道(Notification Channel)发送。如果未正确配置通知渠道,通知可能不会弹出。
- 解决方案:
- 在创建通知时,确保指定了正确的通知渠道:
const channelId = 'your_channel_id'; const channelName = 'Your Channel Name'; const importance = plus.android.IMPORTANCE_HIGH; // 设置通知重要性为高 plus.android.createNotificationChannel(channelId, channelName, importance); const notification = { title: 'Title', content: 'Content', channelId: channelId }; plus.push.createMessage(notification);
- 在创建通知时,确保指定了正确的通知渠道:
3. 通知重要性设置过低
- 原因: 如果通知的重要性设置过低,通知可能不会弹出,而只会显示在通知栏。
- 解决方案:
- 确保通知的重要性设置为
IMPORTANCE_HIGH
或更高:const importance = plus.android.IMPORTANCE_HIGH; plus.android.createNotificationChannel(channelId, channelName, importance);
- 确保通知的重要性设置为