如何实现安卓开机自启动?

2022-09-20 16:33:29 +08:00
 9527H

机型 :vivo Y32 前置条件:已经在设置里面, 打开自启动管理权限

实现代码 AndroidManifest.xml 文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="internalOnly" package="com.harry.broadreceiverstart">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
    android:name=".MyApp"
    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/AppTheme">

    <receiver
        android:name=".AutoStartBroadcastReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>

    <activity
        android:name=".MainActivity"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>

AutoStartBroadcastReceiver.java 文件 package com.harry.broadreceiverstart;

import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.util.Log;

/**

现象:可以接受到开机广播,但是跳转指定的应用失败

另一个问题,小米系列的手机,自启动权限打开以后,也不能监听到开机广播

5000 次点击
所在节点    Android
8 条回复
Kasumi20
2022-09-20 16:36:17 +08:00
这个帖子说明重启手机有用
9527H
2022-09-20 16:39:27 +08:00
重启手机有用?
CharmingCheung
2022-09-20 16:51:53 +08:00
看看 MIUI 的自启动管理是不是限制了
CharmingCheung
2022-09-20 16:56:38 +08:00
跳转指定的应用,是跳其他 App 吗?
是的话,compileSDK>30 吗?
是的话,有没有加 query package 的权限?
CharmingCheung
2022-09-20 16:57:04 +08:00
@CharmingCheung compileSDK >=30
9527H
2022-09-20 17:09:12 +08:00
跳自身应用
bjzhou1990
2022-09-20 17:12:14 +08:00
需要开启后台弹出权限,默认不允许在后台弹出界面
9527H
2022-09-20 19:07:33 +08:00
给了后台弹出权限也不行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/881623

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX