Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 当应用程序在Flatter中关闭时,如何接收本地通知?_Dart_Flutter_Notifications_Localnotification - Fatal编程技术网

Dart 当应用程序在Flatter中关闭时,如何接收本地通知?

Dart 当应用程序在Flatter中关闭时,如何接收本地通知?,dart,flutter,notifications,localnotification,Dart,Flutter,Notifications,Localnotification,我使用软件包。我的应用程序工作正常,打开时会及时发送通知。但如果它被关闭,在它打开之前不会发送通知。如何解决这个问题 AndroidManifest.xml <!-- The INTERNET permission is required for development. Specifically, flutter needs it to communicate with the running application to allow setting breakpoi

我使用软件包。我的应用程序工作正常,打开时会及时发送通知。但如果它被关闭,在它打开之前不会发送通知。如何解决这个问题

AndroidManifest.xml

<!-- The INTERNET permission is required for development. Specifically,
     flutter needs it to communicate with the running application
     to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="test5"
    android:icon="@mipmap/ic_launcher">
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
    <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|locale|layoutDirection|fontScale|screenLayout|density"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- This keeps the window background of the activity showing
             until Flutter renders its first frame. It can be removed if
             there is no splash screen (such as the default splash screen
             defined in @style/LaunchTheme). -->
        <meta-data
            android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
            android:value="true" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>


请注意,确定您正在运行的插件版本,但它要求您已将应用程序迁移到AndroidX,这反过来又需要针对28个插件。例如,请参见

注意,确定您正在运行的插件版本,但它要求您已将应用程序迁移到AndroidX,这反过来又需要确定目标28,例如,通过查看清单文件查看

,它看起来是正确的。我可以问一下你是如何在你的代码中初始化它的吗?我把它添加到了问题中。看起来还可以。在多个android版本/设备中会发生这种情况吗?我一直在iOS和android上使用本地通知,没有任何问题。@MiguelRuivo我用版本9测试了它,但没有正常工作。但现在我正在用android版本5测试它,它可以工作了。@MiguelRuivo在build.gradle中,targetSdkVersion是27。也许我应该把它改成28。通过查看清单文件,它看起来是正确的。我可以问一下你是如何在你的代码中初始化它的吗?我把它添加到了问题中。看起来还可以。在多个android版本/设备中会发生这种情况吗?我一直在iOS和android上使用本地通知,没有任何问题。@MiguelRuivo我用版本9测试了它,但没有正常工作。但现在我正在用android版本5测试它,它可以工作了。@MiguelRuivo在build.gradle中,targetSdkVersion是27。也许我应该把它改成28。
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

  @override
  initState() {
    super.initState();

    var initializationSettingsAndroid =
        new AndroidInitializationSettings('@mipmap/ic_launcher'); 
    var initializationSettingsIOS = new IOSInitializationSettings();
    var initializationSettings = new InitializationSettings(
        initializationSettingsAndroid, initializationSettingsIOS);
    flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
    flutterLocalNotificationsPlugin.initialize(initializationSettings,
        onSelectNotification: onSelectNotification);
  }