API 27无法接收BOOT_COMPLETED操作 [英] BOOT_COMPLETED action cannot be received with API 27

查看:626
本文介绍了API 27无法接收BOOT_COMPLETED操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码虽然可以使用API​​ 25,但不能通过API 27收到 BOOT_COMPLETED 操作。



但是根据官方文档,该操作属于隐式广播示例。 p>

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

 不允许后台执行:接收Intent {act = android.intent.action.BOOT_COMPLETED flg = 0x400010}到com .boottest / .OnBootReceiver 

是否有机会克服此问题?



我的 AndroidManifest.xml 文件:

  ... 
<使用权限android:name = android.permission.RECEIVE_BOOT_COMPLETED />

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

<应用程序...>
....
< receiver android:name =。OnBootReceiver android:exported = true>
<意图过滤器>
< action android:name = android.intent.action.BOOT_COMPLETED />
< / intent-filter>
< / receiver>
< / application>
....

我的 build.gradle 文件:

  ... 
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
}
}
...
}

依赖项{
编译fileTree(dir: libs,包括:[ * .jar])
编译 com.android.support:appcompat-v7:27.0.+
编译 com.facebook.react:react-native:+ //从node_modules
}

allprojects {
储存库{
jcenter()
maven {
url https://maven.google.com
}
}
}

我的 OnBootReceiver.java 文件:

 包com.boottest; 

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

公共类OnBootReceiver扩展了BroadcastReceiver {
@Override
public void onReceive(Context context,Intent intent){
Log.d( BootTest, OnBootReceiver-收到广播!);
}
}


解决方案

问题是Android模拟器。



它可以按预期工作,并且 OnBootReceiver 接收器类的评估结果为 BOOT_COMPLETED 使用Genymotion时启动时的操作。


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

解决方案

The problem was Android Emulator.

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

这篇关于API 27无法接收BOOT_COMPLETED操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆