android - 是否可以使用私有(private) Intent 而不是全局 Intent ?

标签 android android-intent global private public

背景: 我注意到对于其中的常规 Activity ,任何应用程序都可以打开我的应用程序的 Activity 。

问题: 是否可以只允许我自己的应用程序(或应用程序或包)在同一范围内发送和接收 Intent ,以便其他应用程序无法接收它们或干扰应用程序的流程?

例子: 假设我有一个监听某种 Intent 的 broadcastReceiver,但这个 Intent 仅供驻留在我的应用程序内部或我创建的另一个应用程序内部的另一个服务/Activity 使用,但我不想其他人能够使用此 Intent 。

请帮助我。

最佳答案

setPackage()

Set an explicit application package name that limits the components this Intent will resolve to. If left to the default value of null, all components in all applications will considered. If non-null, the Intent can only match the components in the given application package.

或者您可以使用 setSelector() ,但不能同时使用。

关于android - 是否可以使用私有(private) Intent 而不是全局 Intent ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9737908/

相关文章:

android - 横向导航图流预览

android - 如果mp3文件来自端口8443,则音频标签在Cordova Web应用程序中不起作用

android - 如何 Intent 相同的 Activity 而不是第二个 Activity

matrix - 将全局分层旋转转换为局部旋转并返回

android - 同步 SQLite 数据库和 Dropbox 数据存储

android - 单例构造函数使我的应用程序崩溃

android - Intent 回到以前的 Activity 崩溃

android - 从主要 Activity (按钮)启动 map View

C:在文件之间传递变量

php - 如何定义一个 php 类的全局实例?