Marshmallow Intent.ACTION_BOOT_COMPLETED

前提是你 提交于 2019-12-12 03:28:49

问题


i have a rotted Nexus6 With Android6. I've created a system app (located in system/app) i wish to execute a simple code when receiving ACTION_BOOT_COMPLETED but for some reason the code does not executes..

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.atest">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

        <receiver
            android:name="com.atest.testReceiver">
            <intent-filter android:enabled="true">
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

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

Receiver:

public class testReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            // Some simple code
        }
    }
}

Any suggestions?

EDIT: When executing with adb the following:

am broadcast -a android.intent.action.BOOT_COMPLETED -p com.atest

The code execute as expected, but still when rebooting/booting, no success..

来源:https://stackoverflow.com/questions/36983261/marshmallow-intent-action-boot-completed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!