最近开发app遇到一个问题,软件需要再设备开机后进行自动启动,但是由于技术栈使用的uni-app,就卡在了原生插件的运用,试了很多插件,都不太行,最后找到了一个曲线救国的方案,特此进行记录。
Android 开机自启动方案
在HBuilderX中,在根目录右键菜单 “新建” -> “自定义文件”
输入文件名称 AndroidManifest.xml(注意大小写敏感),点击 “创建” 按钮新建文件
然后,填入Android原生的自启动配置(注意替换为你的名包)
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="33" android:compileSdkVersionCodename="13" package="你的包名" platformBuildVersionCode="33" platformBuildVersionName="13">
<application android:allowBackup="false" android:allowClearUserData="true" android:appComponentFactory="androidx.core.app.CoreComponentFactory" android:debuggable="false" android:extractNativeLibs="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:largeHeap="true" android:name="io.dcloud.application.DCloudApplication" android:supportsRtl="true" android:usesCleartextTraffic="true">
<activity android:configChanges="fontScale|keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize" android:exported="true" android:hardwareAccelerated="true" android:label="@string/app_name" android:name="io.dcloud.PandoraEntry" android:screenOrientation="user" android:theme="@style/DCloudTranslucentTheme" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
</activity>
</application>
</manifest>
最后在HBuilderX中提交云打包。