Java 无法使用API 27接收引导\u完成的操作

Java 无法使用API 27接收引导\u完成的操作,java,android-8.1-oreo,Java,Android 8.1 Oreo,下面的代码不接收API 27的BOOT_COMPLETED操作,尽管它可以与API 25一起使用 然而,这一行动是隐含的广播例外根据 当我输入am broadcast-a android.intent.action.BOOT_COMPLETED的adb命令时,控制台上显示以下消息: Background execution not allowed: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x400010 }

下面的代码不接收API 27的
BOOT_COMPLETED
操作,尽管它可以与API 25一起使用

然而,这一行动是隐含的广播例外根据

当我输入
am broadcast-a android.intent.action.BOOT_COMPLETED
的adb命令时,控制台上显示以下消息:

Background execution not allowed: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x400010 } to com.boottest/.OnBootReceiver
有没有克服这个问题的机会

我的
AndroidManifest.xml
文件:

...
<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>
....
...
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"
        }
    }
}
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!");
  }
}
我的
onbootceiver.java
文件:

...
<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>
....
...
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"
        }
    }
}
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!");
  }
}

问题是Android模拟器


当使用Genymotion时,它会按预期工作,并且
OnBootReceiver
receiver类会评估
BOOT\u COMPLETED
启动时的操作。

而不是使用
adb
,您在重新启动设备或仿真器时会获得控制权吗?它在像素2上运行良好,使用modified,将
compileSdkVersion
targetSdkVersion
设置为27。我使用Android Emulator,当我重新启动Emulator时,关于我的应用程序的唯一一行是:
W installd:ignore/data/data/com.bootest/lib,带有意外的GID 0,而不是10079
。感谢您花时间阅读我的邮件:)::耸耸肩::在硬件上试用。也许这是一个模拟器的问题。问题是Android模拟器。如果您使用的是本周发布的以快照为中心的新emulator,请记住,启动emulator不会启动AVD,而只是恢复快照。我假设有一种方法可以重新启动当前的模拟器,尽管我还没有研究它。新的模拟器通过模拟电源按钮,提供了与真实设备一样的重新启动系统的功能。我尝试了重新启动和adb命令来广播
BOOT\u已完成的操作。他们不为我工作。还有一个问题我想不出来。此外,Genymotion是一个预览版本。没有工作的GPS和网络服务。我一直在尝试用新的API更改运行我的应用程序(比如新的后台执行限制)。使用模拟器显然并不容易。