如何限制广播到自己的Android应用程序

前端之家收集整理的这篇文章主要介绍了如何限制广播到自己的Android应用程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道是否有可能创建一个私人广播.
我实际上在我的活动和使用中注册了broadcastreceiver
sendOrderedBroadcast(broadcast);

发送广播的方法.
但是,目前,用于此方法的intent(广播)定义如下:

Intent broadcast = new Intent("com.mypackage.broadcast");

因此,声明此包名称的每个外部应用程序都可以监听我发送的内容,而我不想这样做.

那么如何让这个变得不可能,没人能听我的广播?

解决方法

我想你正在寻找 LocalBroadcast Manager.文档说:

It is a helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with sendBroadcast(Intent). One of them is that the data you are broadcasting won’t leave your app,so don’t need to worry about leaking private data.`

详见how to use LocalBroadcastManager?.希望它能帮到你.

原文链接:https://www.f2er.com/android/310197.html

猜你在找的Android相关文章