[真棒通知](9522):无效通知(没有有效的小图标)



当我运行项目时,我正试图向我的flutter项目添加通知,并向我显示此错误:

E/Android:很棒的通知:无效通知(没有有效的小图标(:通知(pri=2 contentView=com.example.test/0x1090085 vibrate=null sound=content://settings/system/notification_sound刻度默认值=0x0标志=0x11颜色=0xff000000vis=PRIVATE((NotificationThread:58(

主轴架飞镖

import 'package:flutter/material.dart';
import 'package:test/page/notification_service.dart';
class MainScreen extends StatefulWidget {
const MainScreen({Key? key}) : super(key:key);
@override
_MainScreenState createState() => _MainScreenState();
}
class _MainScreenState extends State<MainScreen> {
@override
void initState(){
// TODO: implement initState
super.initState();
NotificationService().requestPermission();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GestureDetector(

onTap: (){
NotificationService().showNotification(
1,
'main_channel',
'Test title',
'Test body',
);
},
child: Container(
height: 30,
width: 70,
color: Colors.blue,
child: Text(
"SHOW NOTIFICATION"
),
),
) ,
GestureDetector(
onTap: () {
NotificationService().showScheduledNotification(
1,
'main_channel',
'Test title',
'Test body',
5,
);
},
child: Container(
height: 30,
width: 70,
color: Colors.red,
child: Text(
"SHOW NOTIFICATION2"
),
),
),
],
),
),
);
}
}

notification_service.dart

import 'package:awesome_notifications/awesome_notifications.dart';
class NotificationService{
static final NotificationService _notificationService = NotificationService._internal();

factory NotificationService(){
return _notificationService;
}
NotificationService._internal();
Future<void> initAwesomeNotification()async{
AwesomeNotifications().initialize(
'resource://drawable/ic_applogo',
[
NotificationChannel(
channelKey: 'main_channel', 
channelName: 'main_channel', 
channelDescription: 'main_channel notifications',
enableLights: true,
importance: NotificationImportance.Max,
)
],
);
}
Future<void> requestPermission() async{
AwesomeNotifications().isNotificationAllowed().then((allowed){
if(!allowed){
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
}
Future<void> showNotification(int id,String channelKey,String title,String body) async{
AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: channelKey,
title: title,
body: body,
),
);
}
Future<void> showScheduledNotification(int id, String channelKey, String title, String body, int interval) async {
String localTZ = await AwesomeNotifications().getLocalTimeZoneIdentifier();
AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: channelKey,
title: title,
body: body,
),
schedule: NotificationInterval(
interval: interval,
timeZone: localTZ,
repeats: false,
)
);
}
}

徽标可能导致问题,因此:

尝试用以下null,替换此:'resource://drawable/ic_applogo',

这样你就可以插入另一个图标了,至少在Android上我是这样做的:我删除了所有的"ic_launcher.png";,因为我没有使用它作为应用程序图标的默认值,正是因为它不让资源//工作。之后,我重新安装了应用程序,并为我想要使用的另一个图标设置了目录,例如:resource://drawable/icon_app,然后它工作了,我没有在lib/assets文件夹中测试它的图标,但它可能也工作。

相关内容

  • 没有找到相关文章

最新更新