我正在使用 flutter 本地通知插件在 flutter 应用程序中设置通知。这是它的代码。
await AndroidAlarmManager.oneShot(
Duration(
seconds: 40,
minutes: timeinminpicked - timeinminNow - 1,
days: pickedDate!.difference(DateTime.now()).inDays),
0,
addalarm,
alarmClock: true,
wakeup: true,
exact: true,
allowWhileIdle: true);
Navigator.of(context).pop();
await FlutterLocalNotificationsPlugin().zonedSchedule(
0,
todoController.text,
'Tap to turn OFF',
tz.TZDateTime.now(tz.local).add(Duration(
seconds: 30,
minutes: timeinminpicked - timeinminNow - 1,
days: pickedDate!.difference(DateTime.now()).inDays)),
const NotificationDetails(
android: AndroidNotificationDetails('your channel id',
'your channel name', 'your channel description')),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
}
在 VS code 上以调试模式运行它时,通知准时出现,但是当我在已发布的 apk/ 使用 flutter run --release 上尝试它时,应用程序突然停止了。这就是出现的错误:
ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(error, Missing type parameter., null, java.lang.RuntimeException: Missing type parameter.
E/flutter ( 8874): at c.b.a.O.a.<init>(:3)
E/flutter ( 8874): at com.dexterous.flutterlocalnotifications.a.<init>(Unknown Source:0)
E/flutter ( 8874): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.loadScheduledNotifications(Unknown Source:25)
E/flutter ( 8874): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.saveScheduledNotification(Unknown Source:0)
E/flutter ( 8874): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.zonedScheduleNotification(:2)
E/flutter ( 8874): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.zonedSchedule(:2)
E/flutter ( 8874): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(Unknown Source:255)
E/flutter ( 8874): at d.a.d.a.q.a(Unknown Source:17)
E/flutter ( 8874): at io.flutter.embedding.engine.l.g.c(Unknown Source:25)
E/flutter ( 8874): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(Unknown Source:4)
E/flutter ( 8874): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 8874): at android.os.MessageQueue.next(MessageQueue.java:336)
E/flutter ( 8874): at android.os.Looper.loop(Looper.java:182)
E/flutter ( 8874): at android.app.ActivityThread.main(ActivityThread.java:7782)
E/flutter ( 8874): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 8874): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/flutter ( 8874): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:981)
E/flutter ( 8874): )
E/flutter ( 8874): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597)
E/flutter ( 8874): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158)E/flutter ( 8874): <asynchronous suspension>
E/flutter ( 8874): #2 AndroidFlutterLocalNotificationsPlugin.zonedSchedule (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:137)
E/flutter ( 8874): <asynchronous suspension>
E/flutter ( 8874): #3 FlutterLocalNotificationsPlugin.zonedSchedule (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:300)
E/flutter ( 8874): <asynchronous suspension>
E/flutter ( 8874): #4 _BottomMSheetState.sumbitData (package:reminder/Widgets/BottomMsheet.dart:81)
E/flutter ( 8874): <asynchronous suspension>
E/flutter ( 8874):
I/flutter ( 8874): [{id: 2021-07-06 12:17:17.609807, title: hahB, date: Tue,6/7/2021, time: 12:18}, {id: 2021-07-06 12:18:26.093092, title: hello, date: Tue,6/7/2021, time: 12:19}]
这是我的 Android 清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.reminder">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<application
android:label="reminder"
android:icon="@mipmap/ic_launcher">
<service
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false"
/>
<receiver
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver"
android:exported="false"/>
<receiver
android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
请帮助我了解出了什么问题。 PS:我是一个flutter新手,不习惯java。
这是因为压缩,所以要么在 gradle 8+ 上的 R8 上使用 R8/fullmode 禁用压缩
或者您可以编写混淆器规则来防止压缩(推荐)
请参阅示例应用程序以供参考
我认为对于新项目,可能需要根据 Kotlin 版本、gradle 设置等进行一些更改,在这种情况下,请搜索 Android 开发人员文档或在此处发表评论。