setPackage的意图姜饼 [英] setPackage for intent in gingerbread

查看:120
本文介绍了setPackage的意图姜饼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照的android文档

另外,从ICE_CREAM_SANDWICH,你也可以放心地限制广播与Intent.setPackage一个单一的应用程序

Alternatively, starting with ICE_CREAM_SANDWICH, you can also safely restrict the broadcast to a single application with Intent.setPackage

有姜饼任何方式(使用兼容性库也许)来限制sendBroadcat()事件,使得它只能将其发送到指定的包?

Is there any way in Gingerbread (using the compatibility library perhaps) to restrict a sendBroadcat() event such that it only sends it to a specified package?

推荐答案

我的第一个建议是使用的 LocalBroadcastManager 如果在所有可能的。这使您可以完全忽略任何安全问题。

My first suggestion would be to use LocalBroadcastManager if at all possible. This allows you to completely ignore any security issues.

如果你确实需要从一个应用程序发送的广播到另一个,这的确是事实,registerReceiver()不尊重setPackage限制,直到ICS所以你不能依靠它在那之前。没有秘招做你想要什么,它只是平台不具备的设施了。

If you really do need to send the broadcast from one app to another, it is indeed true that registerReceiver() did not respect the setPackage restriction until ICS so you can not rely on it until then. There is no secret trick to do what you want, it's just that the platform doesn't have the facility for it.

这是说...如果你要指定一个明确的包名的地步,为什么不走一路,并使用<一个href="http://developer.android.com/reference/android/content/Intent.html#setComponent%28android.content.ComponentName%29"相对=nofollow> Intent.setComponent()?

That said... if you are to the point of specifying an explicit package name, why not just go all the way and use Intent.setComponent()?

也请记住,即使setPackage()或setComponent()不会自动完全安全的 - 你还在做,你知道是谁实施了包名的假设,这是完全可能的不同的应用程序比您希望通过侧载安装,即使你自己在Play商店的名称。

Also keep in mind that even setPackage() or setComponent() are not automatically completely secure -- you are still making an assumption that you know who is implementing that package name, and it is entirely possible for a different app than what you expect to be installed through side-loading, even if you own the name in the Play Store.

这篇关于setPackage的意图姜饼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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