BOOT_COMPLETED action cannot be received with API 27

落花浮王杯 提交于 2019-12-14 03:47:13

问题


The code below does not receive BOOT_COMPLETED action with API 27 although works with API 25.

However this action is among Implicit Broadcast Exeptions according to the official documentation.

When I enter the adb command of am broadcast -a android.intent.action.BOOT_COMPLETED the message below is shown on the console:

Background execution not allowed: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x400010 } to com.boottest/.OnBootReceiver

Is there any chance to overcome this issue?

My AndroidManifest.xml file:

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

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="27" />

<application ... >
    ....
    <receiver android:name=".OnBootReceiver" android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
</application>
....

My build.gradle file:

...
android {
    compileSdkVersion 27
    buildToolsVersion "27.0.1"

    defaultConfig {
        applicationId "com.boottest"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    ...
}

dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:27.0.+"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

My OnBootReceiver.java file:

package com.boottest;

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

public class OnBootReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
        Log.d("BootTest", " OnBootReceiver - Received a broadcast!");
  }
}

回答1:


The problem was Android Emulator.

It works as expected and OnBootReceiver receiver class evaluates BOOT_COMPLETED action on startup when using Genymotion.



来源:https://stackoverflow.com/questions/47908463/boot-completed-action-cannot-be-received-with-api-27

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