下面的代码虽然可以使用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 maven.google } } }我的 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/.OnBootReceiverIs 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 "maven.google" } } }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
发布评论