在不使用显式意图的情况下仅将广播意图发送给一个应用程序 [英] send broadcast intent to only one application without using explicit intent

查看:72
本文介绍了在不使用显式意图的情况下仅将广播意图发送给一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.我正在做一个外部android服务,应用程序可以在该处注册以接收信息.信息通过广播从服务返回到应用程序,并以broadcastReceiver接收.

I have a problem. I'm doing a external android service where applications can register to it to receive information. The information come back to the apps from the service via broadcast, and receive it with a broadcastReceiver.

问题是,如果我执行sendBroadcast,则任何应用程序都可以收听针对他人的信息,我可以在意图过滤器上使用类别,但是两个应用程序都可以将其归为同一类别,或者恶意应用程序可以执行这是有目的的.

The problem is if I do sendBroadcast, any app can listen the information that is for others, I can use the category on the intent filter, but both apps can have it the same category, or a malicous app can do this one on pourpose.

解决方案是显式意图,但是为此,我需要应用程序向程序包和将接收该意图的类进行注册.我不喜欢这种解决方案.

A solution is explicit intents, but for this I need the app to register with the package and the class where it will receive the intent. I don't like this solution.

我认为存在另一种解决方案,因为GCM如此相似,除了broadcastreceiver

I think there exists another solution, because GCM does so similar and doesn't need anything but the broadcastreceiver

我添加了一个小图:

是否存在仅向特定应用发送广播而不定义类的可能性?

Does the possibility exist to send a broadcast only to a specific app, without defining the class??

GCM的效果如何?

How GCM does it?

推荐答案

如果我正确理解了您的问题,那么您担心的是如何使服务安全地将信息发送回客户端.

If I understand your question correctly, your concern is in how to have the service send information back to the clients, securely.

在这种情况下,您可以使用PendingIntent.

In that case, you can use a PendingIntent.

PendingIntentParcelable,因此客户端很容易将其交付给服务.您的服务可以跟踪这些数据,并根据需要对其进行send()跟踪,并为PendingIntent包裹的Intent提供其他数据以放入Intent附加项中.

A PendingIntent is Parcelable, and so it is easy for the clients to deliver to the service. Your service can track these and send() them as needed, supplying additional data to be put into the Intent extras for the Intent wrapped by the PendingIntent.

将响应PendingIntent的组件(活动,服务或接收者)不需要导出.

The component that will respond to the PendingIntent -- activity, service, or receiver -- does not need to be exported.

这篇关于在不使用显式意图的情况下仅将广播意图发送给一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆