gpt4 book ai didi

Android:是否导出了上下文注册的广播接收器?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:48:27 24 4
gpt4 key购买 nike

如果我像这样在我的 Activity 中注册一个广播接收器,

@Override
protected void onResume() {
super.onResume();

myReceiver = new BroadcastReceiver() { ... };
IntentFilter filter = new IntentFilter("com.example.MY_ACTION");
registerReceiver(myReceiver, filter);
}

这个接收器是导出的吗?如果另一个应用程序广播 com.example.MY_ACTION,它会被 myReceiver 接收吗?

如果是,我假设我需要使用接受字符串权限的 registerReceiver() 形式,然后在我的 list 中定义该权限,给它一个高保护级别(例如签名)。那是对的吗?有没有更简单的方法?

最佳答案

来自 BroadcastReceiver API 的 api 文档:

If you don't need to send broadcasts across applications, consider using this class with LocalBroadcastManager instead of the more general facilities described below. This will give you a much more efficient implementation (no cross-process communication needed) and allow you to avoid thinking about any security issues related to other applications being able to receive or send your broadcasts.

这样至少您可以将接收器仅保留在您的应用程序中。

关于Android:是否导出了上下文注册的广播接收器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11675245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com