棉花糖Intent.ACTION_BOOT_COMPLETED

时间:2016-05-02 13:08:59

标签: android root android-6.0-marshmallow android-permissions boot

我的Nexus6Android6 system/app。我已经创建了一个系统应用程序(位于<?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> )我希望在接收ACTION_BOOT_COMPLETED时执行一个简单的代码但由于某种原因代码不会执行..

清单:

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

接收器:

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

有什么建议吗?

修改 使用adb执行以下操作时:

$(this).parent().attr('id')

代码按预期执行,但仍然在重启/启动时,没有成功..

0 个答案:

没有答案