【问题标题】:I always see "E ActivityManager: Sending non-protected broadcast from system" in android 7. What does this mean?我总是在 android 7 中看到“E ActivityManager: Sending non-protected broadcast from system”。这是什么意思?
【发布时间】:2017-04-11 19:33:06
【问题描述】:

我正在尝试使用以下功能从非系统应用程序发送意图。

public static void sendIntent() {
        if (null != _context) {
            Intent intent = new Intent("com.test.testApp.testIntent");
            intent.setPackage(_context.getPackageName());
            _context.sendBroadcast(intent);
        }
    }

但我总是看到来自 ActivityManager 的错误消息如下。相同的意图广播(应用程序)在 andorid 6.0 中工作正常,但在 android 7.1.1 中引发错误。我需要为 android 7.1.1 更改任何内容?

4-10 15:06:34.423 1615 2921 E ActivityManager: 从系统 2886:com.test.testApp/u0a117 pkg com.test.testApp 发送不受保护的广播 com.test.testApp.testIntent

在 ListFragment 中,我按如下方式注册接收器:

 @Override
    public void onStart() {
        super.onStart();
        getActivity().registerReceiver((receiver),
                new IntentFilter(com.test.testApp.testIntent));
        TextView textDownload = (TextView) getActivity().findViewById(R.id.output);
        textDownload.setVisibility(android.view.View.INVISIBLE);
    }

【问题讨论】:

  • 在这个链接中检查后台优化:developer.android.com/about/versions/nougat/…希望这会有所帮助
  • :: shrug :: 尝试更改名称,尤其是 STATUS_CHANGE 位,以防在 Android 检查操作字符串以查看可以发送和不能发送的内容时出现一些奇怪的错误。另请注意,一旦您的targetSdkVersion 上升到O 或更高(或任何O 在Android O 以最终形式发布后变为),像这样的隐式广播在Android O 上不起作用。您不妨考虑使用其他东西。
  • “为什么我会收到这个错误”——也许是 Android 中的一个错误。你用什么设备或模拟器来测试这个? “还有哪些不同的方法可以让我的应用程序成为系统应用程序”——构建您自己的自定义 ROM。
  • "有没有其他方法可以让安卓应用成为系统应用?" - 不。您可以使用android.uid.system 的唯一方法是,您的应用使用与其他预安装应用签名相同的签名密钥进行签名,这需要您构建自定义 ROM。
  • FWIW,我无法重现您的问题。当我将该代码放入活动的onCreate() 时,使用sendBroadcast(new android.content.Intent("com.testApp.savi.STATUS_CHANGE")); 发送广播在Android 7.1 上工作得很好。我没有收到您引用的错误。

标签: android android-intent android-broadcastreceiver android-7.1-nougat


【解决方案1】:

这可能会有所帮助,

如果您在 AndroidManifest.xml 中声明了“android:sharedUserId="android.uid.system",则声明受保护的广播。

参考:https://stackoverflow.com/a/50240471

【讨论】:

    猜你喜欢
    • 2012-04-21
    • 2020-08-31
    • 1970-01-01
    • 2016-11-15
    • 2023-03-25
    • 2022-10-21
    • 2010-11-06
    • 2016-02-06
    • 1970-01-01
    相关资源
    最近更新 更多