|
发表于 2023-5-4 17:42:32
|
显示全部楼层
我用AIO-3568J这个板开发一款开机自启app,代码写好之后,开机不自启- #####AndroidManifest.xml 代码如下###
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.ceshi.ziqi"
- android:installLocation="internalOnly">
- <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <!-- 允许改变wifi连接状态 -->
- <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- 允许应用获取网络状态信息 -->
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 允许应用获得WiFi信息 -->
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 获取位置信息 -->
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 获取手机状态 -->
- <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <!-- 读写SD卡 -->
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.INTERNET" />
- <!-- 悬浮窗 -->
- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:roundIcon="@mipmap/ic_launcher_round"
- android:supportsRtl="true"
- android:theme="@style/Theme.MedicineBoxAndroid">
- <activity
- android:name=".MainActivity"
- android:exported="true">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <!-- 开机启动广播接收器 -->
- <receiver android:name=".receiver.BootReceiver"
- android:enabled="true"
- android:exported="true">
- <intent-filter android:priority="1000">
- <action android:name="android.intent.action.BOOT_COMPLETED"/>
- <category android:name="android.intent.category.DEFAULT" />
- </intent-filter>
- </receiver>
- </application>
- <!-- 开、关机状态权限 -->
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
- </manifest>
- ##########开机广播接收器BootReceiver内容如下#######
- public class BootReceiver extends BroadcastReceiver {
- private static final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
- private Context mContext;
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- mContext = context;
- if (BOOT_ACTION.equals(action)){//开机启动广播
- bootEvent();
- }
- }
- private void bootEvent(){
- Intent intent = new Intent(mContext, MainActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- mContext.startActivity(intent);
- }
- }
复制代码 |
|