How run background process with the work manager in flutter?

后端 未结 1 696
臣服心动
臣服心动 2021-01-23 07:25

I want to work with Flutter Workmanager, I did the cited configuration in my .kt like that

package com.example.mybackprocess

import be.tramckrijte.workmanager.W         


        
相关标签:
1条回答
  • 2021-01-23 07:46

    There are something wrong with the documentation. You can try with this

    Don't remove your .MainActivity.kt, instead remove your .App class.

    MainActivity.kt

    package your_package_name
    
    import androidx.annotation.NonNull
    import io.flutter.embedding.android.FlutterActivity 
    import io.flutter.embedding.engine.FlutterEngine    
    import io.flutter.plugins.GeneratedPluginRegistrant 
    
    class MainActivity: FlutterActivity() { 
        override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {    
            GeneratedPluginRegistrant.registerWith(flutterEngine);  
        }   
    }
    

    AndroidManifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your_package_name">
    
        <uses-permission android:name="android.permission.INTERNET" />
    
        <!-- 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:label="xxx" android:usesCleartextTraffic="true" android:icon="@mipmap/ic_launcher">
            <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" 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>
    
                <intent-filter>
                    <action android:name="FLUTTER_NOTIFICATION_CLICK"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                </intent-filter>
    
                <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" />
    
                <!-- Theme to apply as soon as Flutter begins rendering frames -->
                <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" />
    
            </activity>
    
            <meta-data android:name="flutterEmbedding" android:value="2" />
    
        </application>
    </manifest>
    

    styles.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
            <!-- Show a splash screen on the activity. Automatically removed when
                 Flutter draws its first frame -->
            <item name="android:windowBackground">@drawable/launch_background</item>
        </style>
    
        <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
        <item name="android:windowBackground">@drawable/launch_background</item>
    </style>
    </resources>
    
    0 讨论(0)
提交回复
热议问题