手机在颤动中重新启动后重新启动应用程序

时间:2021-07-06 13:03:43

标签: android flutter restart

我想重新启动我的 Flutter 应用程序以在手机重新启动后自动重新启动。 我已经在 android native 中完成了此操作,但现在我希望在我的 flutter 应用程序中使用相同的功能,并在 flutter 中尝试了此方法,但它在那里不起作用。任何帮助将不胜感激

这是我的 Android 原生代码,用于在移动设备重启后重新启动应用程序。

在清单中

<receiver
            android:name=".BroadcastReceiver.RebootReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
            </intent-filter>
        </receiver>

RebootReciever 类:

public class RebootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
                Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction())
        ) {
            Intent mainIntent = new Intent(context, com.expo.exposports.ExpoMainActivity.class);
            mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(mainIntent);
        }
    }

0 个答案:

没有答案