我正在编写一个Android应用程序,该应用程序应在手机启动时自动启动服务。 Apparently,在Android 3.1之后,如果尚未通过手动单击其图标来启动该应用程序,或者刚被强制停止(以阻止病毒),则将禁用BOOT_COMPLETED广播。我正在编写系统应用程序,因此我的应用程序没有要单击的图标。 Apparently apparently,这不适用于/ system分区中安装的应用程序,但是我的服务无法启动。有没有办法绕过这个,或者至少让Android认为该应用程序已经运行?我正在使用植根电话。我尝试使用am startservice --include-stopped-packages com.test.test/.MainService
启动该服务,但它只显示Error: Not found; no service started.
。这是我的AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.test">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<receiver android:name=".BootStart">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<service android:name=".MainService"
android:exported="true">
<intent-filter>
<action android:name="com.test.test.MainService"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</service>
</application>
</manifest>
作为解决方法,创建一个空的(透明)活动,该活动将立即完成并由程序包管理器启动。