API 27无法接收BOOT

编程入门 行业动态 更新时间:2024-10-25 22:32:18
本文介绍了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 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/.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 "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

本文发布于:2023-11-27 10:32:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:API   BOOT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!