android - 广播接收器在 oreo 和 pie android 中不起作用

标签 android broadcastreceiver android-8.0-oreo android-9.0-pie

启动广播接收器不工作,onReceive() 中没有任何内容

public class BootReceived extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

    if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
        Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show();

        Log.d("IfWalaBooot", intent.getAction());

        Intent intent1 = new Intent(context, MainActivity.class);
        intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent1);

        Intent tni = new Intent(context, MainService.class);
        tni.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startService(tni);

    }

最佳答案

  1. 确保您已在 Manifest 中注册您的接收器。
  2. Implicit Broadcast Exceptions请参阅此链接以检查您的隐式接收器是否 是否在异常(exception)列表中。
  3. 如果没有异常(exception),您可以制作作业调度程序或在您的代码本身中注册您的接收器。这是一个不错的 fragment ,您可以引用 It’s time to kiss goodbye to your implicit BroadcastReceivers

关于android - 广播接收器在 oreo 和 pie android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55429554/

相关文章:

android - Gradle Android - 遗留测试项目结构的测试覆盖率

java - Android - 在文件中查找字符串,如果存在则使用 eclipse 获取该行

android - 联络号码格式的差异

android - 如何让用户恢复到应用自定义声音?

android - 如何在 Android O 中动态更改通知声音

android - 无法使用Android Studio构建应用程序,但可以从终端

android - BroadcastReceiver的onReceive是否并发运行?

android - 为 BroadcastReceiver 创建我自己的操作

android - 如何在android 8.0中设置带有自定义声音的通知?

android - 如何从android中的USB驱动器读取文件?