android - bindService 将客户端限制为特定应用

标签 android service

我需要一种方法来限制对特定应用程序的服务使用。也就是说,我有一个包含用户可以安装的服务的应用程序和一个配套应用程序。我只希望配套应用能够使用该服务。我使用 bindIntent 调用该服务。

我一直在查看客户端的包是否是传递给 onBind 的 Intent 的一部分,但没有看到。在服务中,有没有办法获取客户端的包?

是否有任何其他方法来识别不能被欺骗的客户端应用程序?我可以在服务 list 中添加什么吗?

最佳答案

service Manifest.xml 中的元素可用于控制:

<service
    ...
    android:exported="false" />

Whether or not components of other applications can invoke the service or interact with it — true if they can, and false if not. When the value is false, only components of the same application or applications with the same user ID can start the service or bind to it.

关于android - bindService 将客户端限制为特定应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53751935/

相关文章:

java - 尝试发送csv文件但权限失败

ruby-on-rails - 我怎样才能使这个方法更简洁?

java - 服务 Intent getaction 和 getextra 返回 null

asp.net - 运行后台进程/任务更新数据库

java - 使用 OutOfMemoryException 调用订阅者 onError() 时出现 IllegalStateException

android - Robolectric 3.0 在 DefaultPackageManager.getActivityInfo() 上抛出 Nullpointer

java - Android Volley Request转iOS NSURL异步请求

java - 我怎样才能在 Android Studio 中输出 "comment"整个类

带有 GUI 工具的 Java 服务

Java 应用程序作为 Windows 服务