无法在Oreo上发送广播

问题描述 投票:0回答:1

我正在尝试将应用程序A的广播发送到Lenovo Tablet上的Android O中的Android O中的B,但似乎无法正常工作,并且在控制台上收到这样的消息:

2020-01-08 13:27:22.507 1109-1204/? W/BroadcastQueue: TabletMaster Service: not allowed to launch app com.hp.hpinstaller/10140 for broadcast Intent { act=com.hp.installer.INSTALL_APP flg=0x1000030 cmp=com.hp.hpinstaller/com.hp.installer.InstallBroadcastReceiver (has extras) }

在先前版本的Android平板电脑上运行正常。这是我的代码:从应用程序A

 checkUpdateIntent.setComponent(new ComponentName("com.hp.hpinstaller", "com.hp.installer.InstallBroadcastReceiver"));
 checkUpdateIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
 context.sendBroadcast(checkUpdateIntent);

App B

<receiver
android:name="com.hp.installer.InstallBroadcastReceiver"
android:enabled="true" android:exported="true">
 <intent-filter>
  <action android:name="com.hp.installer.INSTALL_APP"/>
</intent-filter>
</receiver>

<activity android:name="com.hp.installer.MainActivity" android:theme="@android:style/Theme.NoDisplay">
</activity>

build.gradle:

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.0"
    defaultConfig {
        applicationId "com.hp.hpinstaller"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        archivesBaseName = "hpinstaller"
    }

任何人都知道android O在发送和接收广播消息方面有任何变化吗?

android android-broadcast
1个回答
0
投票

摘自Android开发者文档:

Android 8.0

从Android 8.0(API级别26开始,系统对清单声明的接收者施加了其他限制。

[如果您的应用程序针对Android 8.0或更高版本,则您不能使用清单为大多数隐式广播(不专门针对您的应用程序的广播)声明接收方。当用户正在积极使用您的应用时,您仍然可以使用上下文注册的接收器。

您不能再这样做了。用户必须使用该应用程序,并且您可以在existint上下文中声明接收方。

[对于Android 9和10,它的限制更大。

https://developer.android.com/guide/components/broadcasts

© www.soinside.com 2019 - 2024. All rights reserved.